ai_saas_app
ai_saas_app copied to clipboard
🚀 Fix Clerk OAuth User Creation Issue in MongoDB
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.