Skip to content

feat(auth): add Google OAuth authentication - #124

Merged
Akash504-ai merged 7 commits into
CodePlaygroundHub:mainfrom
TejasNere99:feat/google-oauth-authentication
Jul 27, 2026
Merged

feat(auth): add Google OAuth authentication#124
Akash504-ai merged 7 commits into
CodePlaygroundHub:mainfrom
TejasNere99:feat/google-oauth-authentication

Conversation

@TejasNere99

@TejasNere99 TejasNere99 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

fixes : #122
This PR adds Google OAuth authentication to the application, allowing users to securely sign in or sign up using their Google account.

The authentication pages were updated to include the Google Sign-In option while preserving the existing authentication flow.


Changes Made

Backend

  • Added Google OAuth token verification using google-auth-library.
  • Added a new /auth/google endpoint.
  • Supports both:
    • Existing users signing in with Google.
    • New users creating an account using Google.
  • Automatically links an existing local account with a Google account using the same email.
  • Added support for provider and googleId in the User model.

Frontend

  • Integrated Google Sign-In using @react-oauth/google.
  • Added Google authentication to both Login and Signup pages.
  • Reused the existing authentication flow for a seamless user experience.
  • Added loading states and error handling.
  • Updated the authentication page layout to accommodate the Google Sign-In button without affecting the existing flow.

Testing

  • Email login
  • Email signup
  • Google login
  • Google signup
  • Existing user with Google account
  • New user account creation
  • No existing authentication flow was broken

Screenshots

image image Screenshot 2026-07-19 160143

Summary by CodeRabbit

  • New Features

    • Added Google sign-in and sign-up alongside email/password login.
    • Implemented Google authentication that validates Google ID tokens, restricts access to verified Google emails, and issues app JWTs.
    • Supports creating new Google accounts and associating Google identity with existing user accounts.
  • UI Improvements

    • Updated login and registration screens with Google buttons, an “OR” divider, loading spinners, and toast-based error handling.
  • Backend Updates

    • Extended user accounts with OAuth provider info and a Google identity identifier.
    • Added a new Google auth endpoint and improved credential validation behavior.
  • Configuration / Setup

    • Added Google OAuth client ID to frontend and backend environment examples.

@vercel

vercel Bot commented Jul 19, 2026

Copy link
Copy Markdown

@TejasNere99 is attempting to deploy a commit to the Akash Santra 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6fc0c11c-4532-42f0-919a-980169af6db4

📥 Commits

Reviewing files that changed from the base of the PR and between 37d2526 and 9f8a718.

📒 Files selected for processing (4)
  • backend/.env.example
  • backend/src/controllers/auth.controller.js
  • backend/src/models/user.model.js
  • backend/src/routes/auth.route.js
🚧 Files skipped from review as they are similar to previous changes (4)
  • backend/.env.example
  • backend/src/routes/auth.route.js
  • backend/src/models/user.model.js
  • backend/src/controllers/auth.controller.js

📝 Walkthrough

Walkthrough

Google OAuth sign-in and sign-up are implemented across backend authentication, user persistence, and frontend flows, including token verification, account linking or creation, Google UI controls, and authenticated session storage.

Changes

Google OAuth authentication

Layer / File(s) Summary
OAuth configuration and user schema
backend/.env.example, backend/package.json, backend/src/models/user.model.js, frontend/.env.example, frontend/package.json
Adds Google client configuration and authentication dependencies, while allowing provider users without passwords and storing provider metadata.
Google authentication endpoint
backend/src/controllers/auth.controller.js, backend/src/routes/auth.route.js
Verifies Google ID tokens, links or creates users, returns JWT user data, adds a missing-password login guard, and exposes POST /google.
Frontend Google sign-in and sign-up
frontend/src/main.jsx, frontend/src/store/useAuthStore.js, frontend/src/pages/LoginPage.jsx, frontend/src/pages/SignUpPage.jsx
Configures the Google provider, adds Google login controls and loading states, validates login input, and persists successful authentication.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Frontend
  participant GoogleOAuth
  participant googleAuth
  participant UserModel
  Frontend->>GoogleOAuth: Obtain Google ID token
  Frontend->>googleAuth: POST /auth/google with token
  googleAuth->>GoogleOAuth: Verify ID token
  GoogleOAuth-->>googleAuth: Verified email and profile
  googleAuth->>UserModel: Find, link, or create user
  UserModel-->>googleAuth: User record
  googleAuth-->>Frontend: JWT and user profile
Loading

Possibly related issues

  • CodePlaygroundHub/paso-chat-app issue 122 — Covers implementing Google OAuth sign-in and sign-up across the backend and frontend.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding Google OAuth authentication to the auth flow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

backend/src/controllers/auth.controller.js

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

backend/src/models/user.model.js

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

backend/src/routes/auth.route.js

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/src/models/user.model.js (1)

35-39: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Guard password login for Google accounts
googleAuth can create users without a local password, but login still calls bcrypt.compare(password, user.password) unconditionally. For those accounts this returns a 500 instead of a clear “use Google Sign-In” response. Add an early !user.password check in login.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/models/user.model.js` around lines 35 - 39, Update the login
method to check for a missing user.password before calling bcrypt.compare, and
return a clear response directing Google-linked accounts to use Google Sign-In.
Preserve the existing password comparison flow for users with local passwords.
🧹 Nitpick comments (2)
backend/src/models/user.model.js (1)

136-146: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low value

Consider a unique/sparse index on googleId.

googleId has no index constraints. Adding unique: true, sparse: true guards against two user documents ever sharing the same Google account identifier, which is otherwise only implicitly prevented by the email-based lookup in the controller.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/models/user.model.js` around lines 136 - 146, Update the googleId
field in the user model schema to enforce a unique sparse index by adding the
corresponding schema options. Preserve the existing String type and null default
so users without Google accounts remain allowed while duplicate non-null Google
identifiers are rejected.
backend/src/controllers/auth.controller.js (1)

1066-1072: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Token-verification failures return 500 instead of 401.

Any failure inside the try block — including verifyIdToken rejecting an invalid/expired/tampered token — falls through to a generic 500 "Internal Server Error". Distinguishing token-verification errors (401) from true server errors would give the frontend a more accurate signal and avoid masking client-side issues as backend failures.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/controllers/auth.controller.js` around lines 1066 - 1072, Update
the Google authentication error handling around the controller’s verifyIdToken
flow to detect invalid, expired, or tampered token-verification failures and
return HTTP 401 instead of the generic 500 response. Preserve the existing 500
response for unrelated server errors and keep the current error logging context.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/controllers/auth.controller.js`:
- Around line 1028-1052: Update the existing-user branch after User.findOne to
reject banned users and prevent Google linking or authentication for users whose
isVerified flag is false. Apply these checks before assigning googleId, saving
the user, or issuing the JWT, while preserving Google linking for verified,
non-banned users and the existing new-user creation flow.
- Around line 1-11: Add a startup validation immediately after the
`googleClient` initialization to require `process.env.GOOGLE_CLIENT_ID`,
matching the existing `JWT_SECRET` guard’s fail-fast behavior and error-handling
style. Ensure application startup stops when the value is missing, before any
token verification can occur.

---

Outside diff comments:
In `@backend/src/models/user.model.js`:
- Around line 35-39: Update the login method to check for a missing
user.password before calling bcrypt.compare, and return a clear response
directing Google-linked accounts to use Google Sign-In. Preserve the existing
password comparison flow for users with local passwords.

---

Nitpick comments:
In `@backend/src/controllers/auth.controller.js`:
- Around line 1066-1072: Update the Google authentication error handling around
the controller’s verifyIdToken flow to detect invalid, expired, or tampered
token-verification failures and return HTTP 401 instead of the generic 500
response. Preserve the existing 500 response for unrelated server errors and
keep the current error logging context.

In `@backend/src/models/user.model.js`:
- Around line 136-146: Update the googleId field in the user model schema to
enforce a unique sparse index by adding the corresponding schema options.
Preserve the existing String type and null default so users without Google
accounts remain allowed while duplicate non-null Google identifiers are
rejected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bbfcb0a6-fe39-40dd-86ff-ccde88070166

📥 Commits

Reviewing files that changed from the base of the PR and between 64c82d1 and d6e6327.

⛔ Files ignored due to path filters (2)
  • backend/package-lock.json is excluded by !**/package-lock.json
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (11)
  • backend/.env.example
  • backend/package.json
  • backend/src/controllers/auth.controller.js
  • backend/src/models/user.model.js
  • backend/src/routes/auth.route.js
  • frontend/.env.example
  • frontend/package.json
  • frontend/src/main.jsx
  • frontend/src/pages/LoginPage.jsx
  • frontend/src/pages/SignUpPage.jsx
  • frontend/src/store/useAuthStore.js

Comment thread backend/src/controllers/auth.controller.js Outdated
Comment thread backend/src/controllers/auth.controller.js
@Akash504-ai

Copy link
Copy Markdown
Member

Thanks for the contribution! The implementation looks good overall. Before I review it further, please address the security issues highlighted by CodeRabbit, especially the isVerified/isBanned checks and the missing GOOGLE_CLIENT_ID validation. Once those are fixed, I'll take another look.

TejasNere99 and others added 3 commits July 20, 2026 19:39
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Refactor Google OAuth client initialization to handle undefined GOOGLE_CLIENT_ID gracefully.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/controllers/auth.controller.js`:
- Around line 1048-1055: Update the Google-user lookup in the relevant auth
controller flow to explicitly select the password field before setting it
undefined, ensuring Mongoose persists its removal. In the local login handler,
guard against users without a password and return the existing
invalid-credentials response before calling bcrypt.compare.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 824774c6-ec82-48ee-addb-f9b992714725

📥 Commits

Reviewing files that changed from the base of the PR and between 5e481f3 and 787f322.

📒 Files selected for processing (1)
  • backend/src/controllers/auth.controller.js

Comment thread backend/src/controllers/auth.controller.js
Add validation for missing password in authentication.
@TejasNere99

Copy link
Copy Markdown
Contributor Author

Hi @Akash504-ai,

I've addressed all the CodeRabbit review comments and pushed the required changes. The CI checks are now passing successfully.

Could you please review the PR when you have a chance? If there's anything else that needs to be improved, I'd be happy to make the necessary changes.

Thank you!

@Akash504-ai

Copy link
Copy Markdown
Member

Thanks for the updates! Looks good so far.
I'll start reviewing and merging PRs from the 25th. If I find anything during the review, I'll let you know. Thanks for the contribution!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/src/pages/SignUpPage.jsx (1)

104-115: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Associate every label with its input.

Add stable id values to the full-name, email, password, and recovery-answer inputs, then reference them with htmlFor on the corresponding labels. This is required for accessible form navigation.

Proposed fix
-<label className="label py-1">
+<label htmlFor="signup-email" className="label py-1">

-<input type="email"
+<input id="signup-email" type="email"

-<label className="label py-0.5">
+<label htmlFor={`security-question-${index}`} className="label py-0.5">

-<input type="text"
+<input id={`security-question-${index}`} type="text"

Also applies to: 120-131, 136-147, 200-210

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/SignUpPage.jsx` around lines 104 - 115, Associate each
form label with its input in SignUpPage by adding stable, unique id values to
the full-name, email, password, and recovery-answer inputs and matching those
ids through the corresponding labels’ htmlFor attributes. Update the relevant
input and label blocks, including the sections around the full-name field and
the additional fields noted in the review.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/pages/SignUpPage.jsx`:
- Around line 148-154: Update the password visibility toggle button in
SignUpPage to include a conditional aria-label describing whether it will show
or hide the password, and add aria-pressed reflecting showPassword so
screen-reader users can identify and operate the control.

---

Outside diff comments:
In `@frontend/src/pages/SignUpPage.jsx`:
- Around line 104-115: Associate each form label with its input in SignUpPage by
adding stable, unique id values to the full-name, email, password, and
recovery-answer inputs and matching those ids through the corresponding labels’
htmlFor attributes. Update the relevant input and label blocks, including the
sections around the full-name field and the additional fields noted in the
review.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 758402fe-9aa0-4894-b0dd-978d6fd65055

📥 Commits

Reviewing files that changed from the base of the PR and between 787f322 and 37d2526.

📒 Files selected for processing (3)
  • backend/src/controllers/auth.controller.js
  • frontend/src/pages/LoginPage.jsx
  • frontend/src/pages/SignUpPage.jsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/src/controllers/auth.controller.js
  • frontend/src/pages/LoginPage.jsx

Comment thread frontend/src/pages/SignUpPage.jsx
@Akash504-ai Akash504-ai added enhancement New feature or request frontend backend Backend issue performance security ECSoC26 Required before merging an ECSoC PR. good-pr Bonus +15 XP (excellent overall PR). good-backend Bonus +50 XP (exceptional backend work). good-issue Bonus +10 XP (excellent issue resolution). labels Jul 27, 2026
@Akash504-ai
Akash504-ai merged commit 5bca97f into CodePlaygroundHub:main Jul 27, 2026
4 of 5 checks passed
@TejasNere99
TejasNere99 deleted the feat/google-oauth-authentication branch July 27, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend issue ECSoC26-L2 ECSoC26 Required before merging an ECSoC PR. enhancement New feature or request frontend good-backend Bonus +50 XP (exceptional backend work). good-issue Bonus +10 XP (excellent issue resolution). good-pr Bonus +15 XP (excellent overall PR). performance security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add Google OAuth Authentication for Sign In & Sign Up

2 participants