Skip to content

Conversation

@danielchou777
Copy link
Owner

This implements third-party authentication using Google OAuth 2.0.

Key changes include:

  • Added Passport.js strategy for Google OAuth (passport-google-oauth20).
  • Updated User model (prisma/schema.prisma) to include googleId and provider fields. Hash made optional. IMPORTANT: You'll need to run database migrations manually via npx prisma migrate dev.
  • Modified AuthModule, AuthController, and AuthService to support the Google login flow:
    • New routes: /auth/google and /auth/google/callback.
    • AuthService.validateOAuthLogin handles user lookup/creation based on Google profile.
    • Existing signup and signin adjusted for OAuth users.
  • Added required environment variables (GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_CALLBACK_URL) to .env and .env.test. IMPORTANT: You must configure these variables with actual credentials from Google Cloud Console.
  • Implemented e2e tests (test/app.e2e-spec.ts) for the Google login flow, covering:
    • New user registration via Google.
    • Login for existing Google users.
    • Linking Google account to an existing local user.
    • Tests utilize mocking for service layer dependencies and direct controller invocation for callback handling due to OAuth complexities in e2e.

Manual steps required post-pull:

  1. Run database migrations: npx prisma migrate dev --name add_google_auth_to_user (or a similar name if you prefer).
  2. Configure environment variables in .env with your Google Cloud OAuth credentials.

This implements third-party authentication using Google OAuth 2.0.

Key changes include:
- Added Passport.js strategy for Google OAuth (`passport-google-oauth20`).
- Updated User model (`prisma/schema.prisma`) to include `googleId` and `provider` fields. Hash made optional.
  IMPORTANT: You'll need to run database migrations manually via `npx prisma migrate dev`.
- Modified `AuthModule`, `AuthController`, and `AuthService` to support the Google login flow:
    - New routes: `/auth/google` and `/auth/google/callback`.
    - `AuthService.validateOAuthLogin` handles user lookup/creation based on Google profile.
    - Existing `signup` and `signin` adjusted for OAuth users.
- Added required environment variables (`GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `GOOGLE_CALLBACK_URL`) to `.env` and `.env.test`.
  IMPORTANT: You must configure these variables with actual credentials from Google Cloud Console.
- Implemented e2e tests (`test/app.e2e-spec.ts`) for the Google login flow, covering:
    - New user registration via Google.
    - Login for existing Google users.
    - Linking Google account to an existing local user.
    - Tests utilize mocking for service layer dependencies and direct controller invocation for callback handling due to OAuth complexities in e2e.

Manual steps required post-pull:
1. Run database migrations: `npx prisma migrate dev --name add_google_auth_to_user` (or a similar name if you prefer).
2. Configure environment variables in `.env` with your Google Cloud OAuth credentials.
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.

2 participants