#Anonymous user issue

4 messages · Page 1 of 1 (latest)

plucky shadow
#

After a user sends a message in a chat with an anonymous user

And the user signs in

A full page refresh is required to show the user information

Otherwise it will still show as an anonymous user

buoyant atlasBOT
#

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

#

This issue—where after signing in, the user information does not update from "anonymous" to the authenticated user until a full page refresh—is a known challenge when upgrading anonymous accounts in Convex-based apps.

The root cause is typically a race condition or stale state in the client: after the user signs in, the authentication state and associated user data do not update immediately in the UI. This is because the Convex client and its queries may still be using the old session or token until a full reload occurs, which forces the app to re-fetch everything with the new authenticated context.

Several community members have reported similar issues, especially in React and React Native apps. For example, after upgrading from an anonymous to a real account, the new user data only appears after killing and restarting the app. The migration of data works, but the UI does not reflect the new user state until a hard refresh is performed. This is often due to the Convex client not immediately picking up the new authentication token or session, causing queries to return stale or anonymous data until the app is reloaded or the context is reset. This is also observed in web apps, where a manual refresh is required to update the authentication state and show the correct user informationLogging into new user "doesn't work" on react native since I store state?, "Upgrading" Anonymous accounts to "real" accounts with email.

#

Workarounds and Suggestions:

  • One workaround is to force a reload of the authentication context or the entire app when the user signs in, so that all queries and components re-initialize with the new user state.

  • In React, you can use a key prop on your provider (e.g., using the session ID or token as a key) to force a remount of the context provider, which can help the app pick up the new authentication state without a full page reload. See the example in the thread for how to use the token/sessionId as a key to force a reload:

    <ConvexAuthProvider key={sessionId} client={convex}>
      {children}
    </ConvexAuthProvider>
    

    This approach ensures that when the session or token changes (i.e., after sign-in), the provider and its consumers re-render with the new state"Upgrading" Anonymous accounts to "real" accounts with email.

  • If you are using custom state management or local storage, ensure that you clear or update any cached user data after sign-in to avoid showing stale anonymous information.

Summary:
This is a common issue when upgrading anonymous users, and the recommended solution is to force a reload of the authentication context or the app after sign-in, so the UI reflects the new authenticated user state without requiring a manual refresh. This is a known area for improvement in Convex's auth flow, and future updates (such as with Better Auth) may address this more seamlessly.

If you need a code example or further guidance, let me know your framework (React, React Native, etc.), and I can provide a more tailored snippet.

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