Feat/login api rework#61
Conversation
| type LoginResult struct { | ||
| AccessToken string | ||
| Name string | ||
| Email string | ||
| Role string | ||
| } |
There was a problem hiding this comment.
define UserBasicProfile struct (with json tag) here, and rename LoginResult to
struct AuthResponse {
AccessToken string `json.....
UserProfile UserBasicProfile ....
}also define the role enum again here instead of using string
we do this to prevent mapping between service type and dto type when not needed
| package http | ||
|
|
||
| type UserBasicProfile struct { | ||
| Email string `json:"email"` | ||
| Name string `json:"name"` | ||
| Role string `json:"role"` | ||
| } |
| type LoginResponse struct { | ||
| AccessToken string `json:"access_token"` | ||
| UserProfile UserBasicProfile `json:"user_basic_profile"` | ||
| } | ||
|
|
| func (l *LoginResponse) OutTransform(ctx context.Context) error { | ||
| l.AccessToken = strings.TrimSpace(l.AccessToken) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
the out transform to trim token is not needed since token cant contain space
| type Claims struct { | ||
| jwt.RegisteredClaims | ||
| } |
There was a problem hiding this comment.
why not create the inner claims directly?
| return nil | ||
| } | ||
|
|
||
| func (s *AuthService) Login(ctx context.Context, email string, password string) (AuthResponse, error) { |
There was a problem hiding this comment.
use *AuthResponse instead of AuthResponse to simplify code
|
|
||
| func (s *Server) LoginHandler( | ||
| c fuego.ContextWithBody[LoginRequest], | ||
| ) (auth.AuthResponse, error) { |
There was a problem hiding this comment.
use *auth.AuthResponse instead
| return auth.AuthResponse{}, err | ||
| } | ||
|
|
||
| authResponse, err := s.auth.Login( |
There was a problem hiding this comment.
rename authResponse to response since we are in auth the auth prefix is redundant
| return nil | ||
| } | ||
|
|
||
| func (s *AuthService) Login(ctx context.Context, email string, password string) (AuthResponse, error) { |
There was a problem hiding this comment.
use *AuthResponse instead of AuthResponse to simplify code
| var ( | ||
| ErrSigningMethod = errors.New("unexpected signing method") | ||
| ErrInvalidClaims = errors.New("invalid token claims") | ||
| ) |
There was a problem hiding this comment.
what are these errors used for?
No description provided.