Skip to content

Conversation

@PROJITAKAR
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

This change adds Google OAuth authentication to the SaralSeva platform, allowing users to log in and register with their Google accounts. It improves the user experience with a quick, secure option while keeping existing methods (email/password and mobile OTP) intact.

This feature applies only to the User module.
Google login is not enabled for Admin or Employee, as those roles involve sensitive actions (status changes, schema approvals, grievance handling) that require stricter authentication.

What changes are included in this PR?

Backend

  • Installed google-auth-library for verifying Google ID tokens.
  • Updated userModel:
    • Added googleId and provider fields.
    • Minor schema updates to support Google login flow.
  • Added userController methods:
    • googleLogin → Handles login/registration via Google ID token, verifies token, creates new users, and manages partial/complete registration.
    • completeGoogleRegistration → Captures additional details (mobile, gender, state, country) for users signing up with Google.
  • Updated userRoutes to include new endpoints.

Frontend

  • Installed @react-oauth/google.
  • Updated Login and Register pages with Google login buttons.
  • Added CompleteGoogleRegistration page for collecting missing user info.
  • Added GoogleOAuthProvider in main.jsx and integrated route in app.jsx.
  • Minor fixes across the user module to support the Google login flow.

Environment / Setup

  • Updated README.md to include the new setup instructions.
  • Backend .env:
GOOGLE_CLIENT_ID=YOUR_GOOGLE_OAUTH_CLIENT_ID
  • Frontend /user/.env:
VITE_GOOGLE_CLIENT_ID=YOUR_GOOGLE_OAUTH_CLIENT_ID
  • Google Cloud Console setup:
  1. Application type: Web Application
  2. Authorized JavaScript origins:
    • http://localhost:5173 (development)
    • https://your-production-domain.com (production)
    • Any additional frontend URIs
  3. Redirect URIs: Not required for this setup

Are these changes tested?

  • Backend: Verified Google token validation, user creation, and completion flow.
  • Frontend: Manually tested Google login, registration, and completion of missing fields.
  • Existing email/password and mobile OTP flows remain unaffected.

Are there any user-facing changes?

  • Yes. Users will now see “Continue with Google” options on login and registration pages.
  • Google users may be prompted to complete additional fields (mobile, gender, state, country) after their first login.
  • Two new backend APIs were added: googleLogin and completeGoogleRegistration.
  • No breaking API changes. Existing email/password and mobile OTP flows remain intact.
  • Developers must add new environment variables (GOOGLE_CLIENT_ID for backend and VITE_GOOGLE_CLIENT_ID for frontend) to their .env files as part of setup.

Before

Screenshot 2025-09-07 013621

After

Screenshot 2025-09-07 005033 Screenshot 2025-09-07 005203 Screenshot 2025-09-07 005228

@vercel
Copy link

vercel bot commented Sep 6, 2025

@PROJITAKAR is attempting to deploy a commit to the eccentriccoder01's projects Team on Vercel.

A member of the Team first needs to authorize it.

@PROJITAKAR
Copy link
Contributor Author

Hi, this is my first time contributing to an open-source project, but I have used Vercel before.

Regarding Google OAuth: since this is an open-source project, I cannot share my personal Google Client ID.

To make Google login work on your deployment, you’ll need to create your own Google OAuth Client ID and set it as environment variables:

Backend .env:
GOOGLE_CLIENT_ID=YOUR_GOOGLE_OAUTH_CLIENT_ID

Frontend /user/.env:
VITE_GOOGLE_CLIENT_ID=YOUR_GOOGLE_OAUTH_CLIENT_ID

Google Cloud Console setup:

Question: Should I authorize the deployment on Vercel without a Client ID, or will you provide one to make the Google login work?

@eccentriccoder01 eccentriccoder01 merged commit 64369a6 into eccentriccoder01:main Sep 7, 2025
1 of 4 checks passed
@eccentriccoder01 eccentriccoder01 added enhancement New feature or request good first issue Good for newcomers gssoc25 level 3 labels Sep 7, 2025
@eccentriccoder01
Copy link
Owner

Superb work @PROJITAKAR, it works perfectly fine! Definitely level 3 worthy so I've upgraded the label...Feel free to work on more issues or create new ones, and check out my other GSSoC25 projects too:

  • TalkHeal TalkHeal
  • SaralSeva SaralSeva
  • Venturalink Venturalink
  • Spamlyser Spamlyser
     
    Thanks for improving SaralSeva 🧡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers gssoc25 level 3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Google OAuth Login and Registration for Users

2 participants