Stuck in permanent unauthenticated state after access token expiry (AuthKit, Next.js)
I'm using WorkOS AuthKit together with Convex in a Next.js App Router project, and I'm consistently hitting an auth edge case:
* After the WorkOS access token expires, the next Convex queries that call
auth.getIdentity() throw.
* AuthKit refreshes the token (verified in useAccessToken()).
* The Convex backend starts accepting the new token — new successful queries appear in the Convex dashboard.
* But on the client, useConvexAuth() never recovers and stays:
This permanently locks the UI out until a full page reload.
Things I tried:
* Official ConvexProviderWithAuth example from the docs
* ConvexProviderWithAuthKit from @convex-dev/workos
* Custom useAuth integrations with stable refs and effects
All end up with the same result: once Convex sees an error during the token-refresh window, its client auth state machine seems unable to transition back to authenticated (I think, I could only go so far in reading the source).
This feels related to the previously known preloadQuery auth race
https://github.com/get-convex/convex-backend/issues/242
Full reproducible issue:
https://github.com/get-convex/convex-backend/issues/259GitHub
Race condition when hydrating usePreloadedQuery before Convex clien...
When using WorkOS AuthKit with Convex in a Next.js App Router project, if a query requiring authentication is preloaded on the server (preloadQuery(..., { token })) and then consumed via usePreload...
GitHub
Stuck in permanent unauthenticated state after access token expiry ...
Summary When using WorkOS AuthKit with Convex in a Next.js App Router project, the Convex React client sometimes enters a permanent unauthenticated state after the access token expires. Even though...
1 Reply
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!