[BUG] Social OAuth Sign-Up Fails When Users Schema Contains Custom Required Fields
Bug
Social OAuth sign-up fails when the users schema contains custom required fields. During the OAuth callback, a new user document is created using only the data returned by the provider (email, name, username, avatar, etc.). If the schema has additional required fields (e.g. role, termsAccepted), Mongoose validation fails and the server returns a 500 Internal Server Error, preventing new users from signing up via Google or GitHub.
To Reproduce
Create a custom required field in the users schema (e.g. role with required: true). Enable Google or GitHub authentication. Attempt to sign up using the social login option. Complete the OAuth flow. Observe that the callback fails with a 500 Internal Server Error.
Expected behavior
The OAuth sign-up flow should handle missing required custom fields gracefully by:
1- Allowing users to complete the missing fields after authentication, or 2- Returning a clear validation response instead of a generic 500 error.
Desktop
OS: Windows 11 Browser: Chrome Version: Latest
Smartphone Device: N/A OS: N/A Browser: N/A Version: N/A
Additional context
The issue occurs because the social authentication flow creates a new user with only the OAuth provider data. When additional required fields exist in the users schema, Model.create(newUserPayload) triggers a Mongoose validation error, causing the request to fail with a 500 Internal Server Error instead of providing a recoverable registration flow.
U wanna work on this?? @AYUSH-P-SINGH
yes assign this issue to me Thank you!!
Ok proceed @AYUSH-P-SINGH