fix: get profile user/staff using token rather than id
This commit is contained in:
@@ -2,8 +2,8 @@ package authsvc
|
||||
|
||||
import authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
|
||||
func (as *AuthSvc) GetStaffProfile(id string) (*authdomain.StaffProfile, error) {
|
||||
staff, err := as.staffRepo.GetStaffByID(id)
|
||||
func (as *AuthSvc) GetStaffProfile(email string) (*authdomain.StaffProfile, error) {
|
||||
staff, err := as.staffRepo.GetStaffByEmail(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package authsvc
|
||||
|
||||
import authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
|
||||
func (as *AuthSvc) GetUserProfile(id string) (*authdomain.UserProfile, error) {
|
||||
user, err := as.userRepo.GetUserByID(id)
|
||||
func (as *AuthSvc) GetUserProfile(email string) (*authdomain.UserProfile, error) {
|
||||
user, err := as.userRepo.GetUserProfile(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (sv *AuthSvc) LoginAsStaff(spec authdomain.LoginReq) (string, error) {
|
||||
@@ -18,7 +20,12 @@ func (sv *AuthSvc) LoginAsStaff(spec authdomain.LoginReq) (string, error) {
|
||||
return "", errors.New("wrong password")
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(staff.Email)
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: staff.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
|
||||
@@ -18,7 +20,12 @@ func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
|
||||
return "", errors.New("wrong password")
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(user.Email)
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: user.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
@@ -19,19 +19,24 @@ func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error
|
||||
return "", err
|
||||
}
|
||||
|
||||
user := authdomain.Staff{
|
||||
staff := authdomain.Staff{
|
||||
ID: uuid.NewString(),
|
||||
Email: spec.Email,
|
||||
Password: hashedPwd,
|
||||
Username: spec.Username,
|
||||
}
|
||||
|
||||
_, err = a.staffRepo.Create(&user)
|
||||
_, err = a.staffRepo.Create(&staff)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(spec.Email)
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: staff.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
@@ -48,7 +48,12 @@ func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error)
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(spec.Email)
|
||||
authToken := authdomain.AuthToken{
|
||||
Email: user.Email,
|
||||
SessionID: uuid.NewString(),
|
||||
}
|
||||
|
||||
token, err := utils.GenerateToken(authToken)
|
||||
if err != nil {
|
||||
return "", errors.New(err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user