Skip to content

Fix Google OAuth registration for users without password - #353

Closed
tejas0711 wants to merge 1 commit into
Nsanjayboruds:mainfrom
tejas0711:fix-google-oauth-password-validation
Closed

Fix Google OAuth registration for users without password#353
tejas0711 wants to merge 1 commit into
Nsanjayboruds:mainfrom
tejas0711:fix-google-oauth-password-validation

Conversation

@tejas0711

Copy link
Copy Markdown

Pull Request

Fixes Google OAuth registration failure caused by password validation in the User schema. This change allows users authenticated through Google OAuth to create accounts without requiring a password while preserving password requirements for locally registered users.

Problem

When a new user attempted to sign up using Google Authentication, the backend tried to create a user record with only the user's name and email.
However, the User schema required a password for every user:
password: {
type: String,
required: true,
}
As a result, Google OAuth registration failed with:
Validation Error: password: Path "password" is required.

Solution

Implemented provider-based authentication handling by introducing an auth Provider field in the User schema.
Changes made:

  1. Added Auth Provider field to distinguish between local and Google-authenticated users.
  2. Updated password validation to be conditional:
    Local users (Auth Provider: "local") must provide a password. Google users (Auth Provider: "google") are not required to provide a password.
  3. Updated the Google login flow to create users with:
    Auth Provider: "google"

Benefits

Fixes Google OAuth registration failures.
Preserves existing local authentication behaviour.
Provides a scalable foundation for supporting additional OAuth providers in the future.
Prevents schema validation errors for third-party authentication users.

Testing

Reviewed the user creation flow for Google OAuth registration.
Verified that Google users are now created with Auth Provider: "google"`.
Verified that password validation remains enforced for locally registered users.
Full end-to-end local testing could not be completed because the project requires environment variables (MongoDB connection string and SMTP credentials) that are not available in the local development environment.

Related Issue

Fixes #347

Type of Change

Bug fix

Checklist

Code follows project guidelines
Fix is limited to the affected authentication flow
No unnecessary files included in the PR
No new console errors introduced by the code changes

@tejas0711

Copy link
Copy Markdown
Author

@Nsanjayboruds kindly accept the PR

@Nsanjayboruds

Nsanjayboruds commented Jun 25, 2026

Copy link
Copy Markdown
Owner

@tejas0711 provide screenrecording of your change

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.

[Bug]: Fix Google OAuth Registration Failing Due to Required Password Validation

2 participants