-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Auto-provision users during OAuth login #379
Copy link
Copy link
Open
Copy link
Labels
enhancementNew feature or requestNew feature or request
Description
Background
When users sign in to campus-admin via OAuth (Google, GitHub, etc.), the authentication flow completes but the application crashes with a 500 error:
ServerError: Document/row with id 'test_student@nyjc.edu.sg' not found in collection/table 'users'
Problem Investigation
The OAuth callback flow works like this:
- User clicks "Sign In" → redirected to Google/GitHub/etc.
- Provider redirects back with authorization code
- Backend exchanges code for access token and user info (email, name)
- Credentials are stored in the database
- Session is updated with the user_id
- User is redirected back to campus-admin
However, when campus-admin tries to display the dashboard, it calls push_context() to load the authenticated user's details. This looks up the user in the users table... but the user record was never created in step 4.
Your Task
Implement auto-provisioning of user records during the OAuth callback flow. When a user successfully authenticates via OAuth, their user record should be created automatically if it doesn't already exist.
Key Requirements
- Idempotent operation: If the user already exists, return the existing record
- Minimal database changes: Only create if necessary
- Consistent across providers: All OAuth providers (Google, GitHub, Discord) should use the same mechanism
- Thread-safe: Handle race conditions if two requests try to create the same user simultaneously
Files to Investigate
campus/auth/resources/user.py- User resource with CRUD operationscampus/auth/oauth_proxy/google/proxy.py- Google OAuth callbackcampus/auth/oauth_proxy/github/proxy.py- GitHub OAuth callbackcampus/auth/oauth_proxy/discord/proxy.py- Discord OAuth callback
Acceptance Criteria
- User records are created automatically on first OAuth login
- Subsequent logins retrieve the existing user record
- No 500 errors when new users log in
- All three OAuth providers (Google, GitHub, Discord) work correctly
Testing Hints
- Check the Railway logs for campus-auth after deploying your changes
- Try logging in with a test account that doesn't exist in the database
- Verify the user record is created correctly with email and name
Subscribed: @saltensity
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
Testing/Integration