Skip to content

feat(auth): add Google OAuth2 login (#292)#443

Merged
LaGodxy merged 5 commits into
MettaChain:mainfrom
deborahamoni0-prog:feature/292-google-oauth2-login
Apr 26, 2026
Merged

feat(auth): add Google OAuth2 login (#292)#443
LaGodxy merged 5 commits into
MettaChain:mainfrom
deborahamoni0-prog:feature/292-google-oauth2-login

Conversation

@deborahamoni0-prog
Copy link
Copy Markdown
Contributor

@deborahamoni0-prog deborahamoni0-prog commented Apr 22, 2026

Closes #292


Summary

Implements Google OAuth2 authentication as described in issue #292.

Acceptance Criteria

  • ✅ OAuth2 config (GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_CALLBACK_URL)
  • ✅ Login endpoint (GET /auth/google → redirect, GET /auth/google/callback → tokens)
  • ✅ Account linking (existing email → links googleId)
  • ✅ Profile sync (firstName, lastName, avatar kept in sync on each login)

Changes

  • GoogleStrategy — Passport strategy using passport-google-oauth20, extracts googleId, email, firstName, lastName, avatar from Google profile
  • GoogleAuthGuard — thin guard wrapping AuthGuard('google')
  • AuthService.googleOAuthLogin — handles three cases:
    • New user → creates account (pre-verified, no password required)
    • Existing email → links Google account to existing user
    • Returning Google user → syncs profile fields
  • EndpointsGET /auth/google (redirect) and GET /auth/google/callback (returns access + refresh tokens)
  • SchemaUser.password made optional, googleId unique field added
  • Migration20260422000001_add_google_oauth
  • Dependencies@nestjs/passport@10.0.3, passport-google-oauth20@2.0.0

Config

Add to .env:

GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_CALLBACK_URL=http://localhost:3000/api/auth/google/callback

Verified

  • npm run lint — 0 errors
  • npm run build — passes
  • npm test — 9/9 tests pass

- Add GoogleStrategy using passport-google-oauth20
- Add GoogleAuthGuard wrapping passport 'google' strategy
- Add /auth/google and /auth/google/callback endpoints
- Add googleOAuthLogin to AuthService with account linking and profile sync
- Make User.password optional to support OAuth-only accounts
- Add googleId unique field to User model
- Add migration for schema changes
- Update AuthModule with PassportModule and GoogleStrategy
- Add GOOGLE_CLIENT_ID/SECRET/CALLBACK_URL to .env.example
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 22, 2026

@deborahamoni0-prog Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@deborahamoni0-prog
Copy link
Copy Markdown
Contributor Author

done

@LaGodxy LaGodxy merged commit 9eae541 into MettaChain:main Apr 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Google OAuth2 Login

2 participants