#Hotreload goes to app home page

10 messages · Page 1 of 1 (latest)

visual heath
#

I'm using Expo and React Native and whenever I hot reload or reload the app using the auth context it takes me back to the index page as opposed to staying on the page that I was previously on. Is this a known issue or how can I get around this?

full pilotBOT
#

Hi @visual heath. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Short answer: this typically isn’t a Convex issue, but a routing/auth state reset during reload. In Expo/React Native, hot reload can remount providers, which can briefly flip isAuthenticated/isLoading and trigger your redirect logic back to the “home” or “index” route. Several threads note similar “auth flickers” and route jumps in Expo/Router production vs dev, caused by auth context being lost/remounted and queries re-running on navigation/reload. [Convex queries rerun; WorkOS thread: flicker on refresh]

#

Workarounds you can try:

  • Gate navigation on a stable loading state. Don’t redirect while isLoading is true; only navigate once both your auth provider (Clerk/Convex Auth/custom) and useConvexAuth report a settled state. Several users fixed random redirects by waiting for the Convex auth state before routing. [Logout after inactivity]
  • Put redirect logic on the auth screen itself and listen to isAuthenticated to push when it becomes true, instead of globally redirecting from a parent layout that remounts on reload. [Logout after inactivity]
  • Avoid double-wrapping Convex providers and ensure your auth provider is the single source of truth; double providers caused state confusion for others. [Upgrading anonymous accounts]
  • If you use a custom auth integration, ensure token storage survives reloads (e.g., SecureStore/Keychain) and that your ConvexProviderWithAuth/useAuth fetchAccessToken doesn’t force-refresh on every remount. Some users switched storage libraries to reduce random reauth. [Logout after inactivity; WorkOS custom auth example]
  • In stubborn cases, force a subtree remount when the session actually changes (React key trick) so you don’t run redirect logic on transient states during reload. [Upgrading anonymous accounts]
#

If you can share how your redirects are implemented (layout vs screen-level, and where you read isAuthenticated/isLoading), we can suggest a minimal change to stop the reload jump.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@visual heath Kapa.ai is still learning and improving, please let me know how I did by reacting below.

visual heath
#

@full pilot it seems to be due to r9/8/2025, 11:53:22 AM [CONVEX M(auth:store)] [INFO] 'auth:store type: refreshSession'

is there some way to serialize/store the session locally to imrpvoe this?

full pilotBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Short answer: yes—persisting auth/session tokens locally helps avoid flickers during reloads, but the exact approach depends on which auth you use.

  • Convex Auth (convex-auth): Use the provider’s storage prop to persist tokens across reloads (e.g., Expo SecureStore or react-native-keychain). This prevents transient “unauthenticated” states when providers remount and avoids unnecessary refreshes. Example patterns show passing a secure storage adapter to ConvexAuthProvider or ConvexProviderWithAuth so tokens survive reloads. [WorkOS RN storage example; RN secure storage adapter]

  • Clerk + Convex: Memoize your getToken/fetchAccessToken and avoid forcing refresh on every remount; use a stable token cache to prevent constant refreshSession cycles after reload/background resume. Race conditions on resume have been discussed; upcoming fixes target avoiding authenticating expired tokens, but stable local token storage and cautious redirects help now. [Auth token race notes; Logout after inactivity thread]

  • Custom auth: Ensure your fetchAccessToken is wrapped in useCallback so React reloads don’t cause repeated refresh loops, and expect one refresh at startup (by design). [Custom Auth + refresh]

#

If you need session-like IDs for tracking (not auth), convex-helpers provides a SessionProvider that persists a sessionId with localStorage (or a custom storage hook). It also has an ssrFriendly mode for deferring calls until the ID is ready. [Session tracking helpers]

Concrete tips:

  • Persist tokens in SecureStore/Keychain and pass that storage into your Convex auth provider.
  • Memoize getToken/fetchAccessToken; don’t force skipCache unless truly needed.
  • Gate routing on isLoading to avoid redirects during refreshSession blips.
  • If auth state really changes, use a key on the auth provider to remount the subtree only on real session changes, not on reload. [Upgrading anonymous accounts]

If you share which auth stack you’re using (Convex Auth vs Clerk) and your provider setup, I can suggest the exact storage adapter and snippet.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: