Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
fix(auth): google auth (#27)
Browse files Browse the repository at this point in the history
* Fix record duplicate when logging with Google

* Codegen fix
  • Loading branch information
swift1337 authored Aug 1, 2023
1 parent 715a27c commit 1204b51
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
17 changes: 11 additions & 6 deletions internal/db/repository/users.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion internal/service/user/service_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func (s *Service) ResolveWithGoogle(ctx context.Context, user *auth.GoogleUser) (*User, error) {
entry, err := s.store.GetUserByGoogleID(ctx, repository.StringToNullable(user.Sub))
entry, err := s.store.GetUserByEmail(ctx, user.Email)
switch {
case errors.Is(err, pgx.ErrNoRows):
return s.registerGoogleUser(ctx, user)
Expand Down Expand Up @@ -57,6 +57,8 @@ func (s *Service) registerGoogleUser(ctx context.Context, user *auth.GoogleUser)
func (s *Service) updateGoogleUser(ctx context.Context, userID int64, user *auth.GoogleUser) (*User, error) {
entry, err := s.store.UpdateUser(ctx, repository.UpdateUserParams{
ID: userID,
SetGoogleID: true,
GoogleID: repository.StringToNullable(user.Sub),
Name: user.Name,
ProfileImageUrl: repository.StringToNullable(user.Picture),
UpdatedAt: time.Now(),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/api-kms/v1/client/wallet/wallet_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions scripts/queries/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ RETURNING *;

-- name: UpdateUser :one
UPDATE users
SET name = $1,
profile_image_url= $2,
updated_at = $3
WHERE id = $4
SET name = $2,
profile_image_url= $3,
google_id = CASE WHEN @set_google_id::boolean THEN $4 ELSE users.google_id END,
updated_at = $5
WHERE id = $1
RETURNING *;

-- name: UpdateUserPassword :one
Expand Down

0 comments on commit 1204b51

Please sign in to comment.