this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

auth: fix user id type in middleware

Clément 159178ce 91f46b22

+9 -5
+4 -2
backend/internal/middlewares/context.go
··· 3 3 import ( 4 4 "context" 5 5 "errors" 6 + 7 + "github.com/gofrs/uuid" 6 8 ) 7 9 8 - func GetUserID(ctx context.Context) string { 9 - userID, ok := ctx.Value(UserIDKey).(string) 10 + func GetUserID(ctx context.Context) uuid.UUID { 11 + userID, ok := ctx.Value(UserIDKey).(uuid.UUID) 10 12 if !ok { 11 13 panic(errors.New("user id not found")) 12 14 }
+3 -2
backend/internal/services/auth.go
··· 5 5 "database/sql" 6 6 "errors" 7 7 8 + "github.com/gofrs/uuid" 8 9 "uiua.online/internal/models" 9 10 ) 10 11 ··· 41 42 return token, nil 42 43 } 43 44 44 - func (s *AuthService) Whoami(context context.Context, userId string) (string, error) { 45 + func (s *AuthService) Whoami(context context.Context, userId uuid.UUID) (string, error) { 45 46 user, err := s.user.GetFromID(userId) 46 47 if err != nil { 47 48 return "", err ··· 50 51 return user.Email, nil 51 52 } 52 53 53 - func (s *AuthService) ChangePassword(context context.Context, userId string, req models.ChangePasswordRequest) error { 54 + func (s *AuthService) ChangePassword(context context.Context, userId uuid.UUID, req models.ChangePasswordRequest) error { 54 55 user, err := s.user.GetFromID(userId) 55 56 if err != nil { 56 57 return err
+2 -1
backend/internal/services/user.go
··· 4 4 "database/sql" 5 5 "errors" 6 6 7 + "github.com/gofrs/uuid" 7 8 "golang.org/x/crypto/bcrypt" 8 9 "uiua.online/internal/models" 9 10 ) ··· 40 41 return false, errors.New("invalid credentials") 41 42 } 42 43 43 - func (s *UserService) GetFromID(userId string) (*models.User, error) { 44 + func (s *UserService) GetFromID(userId uuid.UUID) (*models.User, error) { 44 45 row := s.db.QueryRow("select * from \"users\" where id = ?", userId) 45 46 var user models.User 46 47 if err := row.Scan(&user.ID, &user.Email, &user.PasswordHash); err != nil {