You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Show loading state during initial token fetch to prevent flash (#297)
* fix: show loading state during initial token fetch to prevent flash
Previously, useAccessToken would report loading:false during the initial token fetch,
creating a race condition where useAuth had finished loading but the token hadn't
arrived yet. This caused downstream consumers to see a brief "unauthenticated" state.
This led to workarounds like adding !accessToken to loading calculations (see
workos/template-convex-nextjs-authkit#5), which then broke for logged-out users.
This fix ensures useAccessToken correctly reports loading:true during initial fetch,
eliminating the race condition at its source. Downstream consumers can now safely
check loading states without needing the !accessToken workaround.
Changes:
- Track initial token fetch with isInitialTokenLoading state
- Report loading:true until initial fetch completes
- Update tests to expect loading state during mount
* Update src/components/useAccessToken.ts
Co-authored-by: Copilot <[email protected]>
* fix: prevent unnecessary loading states for cached tokens
---------
Co-authored-by: Copilot <[email protected]>
0 commit comments