Fix Google OAuth registration for users without password - #353
Closed
tejas0711 wants to merge 1 commit into
Closed
Conversation
Author
|
@Nsanjayboruds kindly accept the PR |
Owner
|
@tejas0711 provide screenrecording of your change |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Local users (Auth Provider: "local"
) must provide a password. Google users (Auth Provider: "google") are not required to provide a password.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