getAuthUserId() Returns Null Despite Successful OAuth Sign-In
getAuthUserId() Returns Null Despite Successful OAuth Sign-In
Issue:
getAuthUserId(ctx) returns null in all backend queries/mutations, even though OAuth sign-in succeeds and creates a valid session.
Environment:
- @convex-dev/auth: ^0.0.90
- Auth provider: Google OAuth
What Works:
- ✅ OAuth sign-in completes
- ✅ Session created in authSessions table
- ✅ JWT stored in browser localStorage
What Doesn't Work:
- ❌ getAuthUserId(ctx) returns null
- ❌ ctx.auth._token is undefined (JWT not sent with requests)
Code:
Frontend (with useConvexAuth):
Backend:
Logs:
What We've Tried:
- Implemented useConvexAuth() to wait for isAuthenticated: true before calling queries
- Verified JWT exists in localStorage
- Cleared all sessions and signed in fresh multiple times
- Used getAuthUserId() from @convex-dev/auth/server
Our auth.config.ts has domain: process.env.CONVEX_SITE_URL which may be undefined. Could this be blocking JWT validation? How should we properly configure authentication?3 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
If
isAuthenticated from useConvexAuth is true, jwt validation is working - you should see Authentication messages in the sync websocket connection with a jwt. If you have a minimal repro I can take a look.Minimal Reproduction Files
1. convex/auth.config.ts:
2. convex/auth.js:
3. convex/users.ts (query):
4. Frontend: AuthContext.jsx (React):
Observed Behavior:
-
isAuthenticated: true after sign-in ✅
- [createOrUpdateUser] logs show correct user ID ✅
- [getCurrentUserProfile] userId: null ❌
- JWT exists in localStorage ✅
@erquhart I don't know if this helps to repro.