ai_saas_app icon indicating copy to clipboard operation
ai_saas_app copied to clipboard

🚀 Fix Clerk OAuth User Creation Issue in MongoDB

Open RahulGurav82 opened this issue 8 months ago • 1 comments
trafficstars

This PR fixes an issue where users signing up with Google OAuth were not found in MongoDB due to webhook delays.

✅ Implemented createOrGetUser to check for existing users before creating new ones. ✅ Updated the user.created webhook handler to use createOrGetUser instead of createUser, preventing duplicate user creation. ✅ Modified getUserById to fetch user data from Clerk and create them if missing in MongoDB, improving resilience. ✅ Ensured smoother user creation flow for both email/password and OAuth signups.

This resolves the "User not found" error caused by a race condition between OAuth completion and webhook delivery.

RahulGurav82 avatar Mar 01 '25 19:03 RahulGurav82