urBackend icon indicating copy to clipboard operation
urBackend copied to clipboard

[BUG] Social OAuth Sign-Up Fails When Users Schema Contains Custom Required Fields

Open AYUSH-P-SINGH opened this issue 4 months ago • 3 comments

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.

AYUSH-P-SINGH avatar Jul 08 '26 19:07 AYUSH-P-SINGH

U wanna work on this?? @AYUSH-P-SINGH

yash-pouranik avatar Jul 10 '26 08:07 yash-pouranik

yes assign this issue to me Thank you!!

AYUSH-P-SINGH avatar Jul 10 '26 11:07 AYUSH-P-SINGH

Ok proceed @AYUSH-P-SINGH

yash-pouranik avatar Jul 10 '26 19:07 yash-pouranik