Skip to content

Commit

Permalink
feat(auth): handle session create in google login
Browse files Browse the repository at this point in the history
  • Loading branch information
tithanayut committed Feb 15, 2025
1 parent 415e3f0 commit 08cb7a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion auth/server/core/port/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type Service interface {
Login(ctx context.Context, email, password, ipAddress, userAgent string) (string, error)
LoginWithGoogle(ctx context.Context, idToken string) (string, error)
LoginWithGoogle(ctx context.Context, idToken, ipAddress, userAgent string) (string, error)
Logout(ctx context.Context, sessionID string) error
GetMe(ctx context.Context, userID string) (*core.Me, error)
}
13 changes: 9 additions & 4 deletions auth/server/core/service/login_with_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/rs/zerolog/log"
)

func (s *Service) LoginWithGoogle(ctx context.Context, idToken string) (string, error) {
func (s *Service) LoginWithGoogle(ctx context.Context, idToken, ipAddress, userAgent string) (string, error) {
l := log.Ctx(ctx)

payload, err := s.googleIDTokenValidator.Validate(ctx, idToken, s.config.GoogleClientID)
Expand Down Expand Up @@ -43,9 +43,14 @@ func (s *Service) LoginWithGoogle(ctx context.Context, idToken string) (string,

*l = l.With().Str("userId", account.ID).Logger()

// TODO: call auth session server to create a new session
session, err := s.authSessionClient.CreateSession(account.ID, ipAddress, userAgent)
if err != nil {
l.Error().Err(err).Msg("[Service.Login] failed to create session")

return "", errors.Wrap(err, "failed to create session")
}

l.Info().Str("sessionId", "TODO").Msg("[Service.LoginWithGoogle] login successfully")
l.Info().Str("sessionId", session.SessionID).Msg("[Service.LoginWithGoogle] login successfully")

return "", nil
return session.SessionID, nil
}
2 changes: 1 addition & 1 deletion auth/server/handler/login_with_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Server) LoginWithGoogle(c echo.Context) error {
return response.BadRequest(c, "invalid request body")
}

sessionID, err := s.service.LoginWithGoogle(ctx, req.IDToken)
sessionID, err := s.service.LoginWithGoogle(ctx, req.IDToken, c.RealIP(), c.Request().UserAgent())
if err != nil {
switch {
case errors.Is(err, core.ErrInvalidCredentials):
Expand Down

0 comments on commit 08cb7a8

Please sign in to comment.