fix: get profile user/staff using token rather than id

This commit is contained in:
ericprd
2025-02-28 12:18:47 +08:00
parent 5fb0764630
commit 6b858b99fb
15 changed files with 234 additions and 44 deletions
+2 -2
View File
@@ -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 -2
View File
@@ -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
}
+8 -1
View File
@@ -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())
}
+8 -1
View File
@@ -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())
}
+8 -3
View File
@@ -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())
}
+6 -1
View File
@@ -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())
}