Logout redirect with cookie caching
Stack:
Better Auth with cookieCache enabled
TanStack Router
React with AuthProvider using authClient.useSession()
Node.js with Express for backend
Issue:
When user clicks logout:
authClient.signOut() succeeds (returns {success: true})
auth.isAuthenticated still returns true in React context
Navigation to /login fails - login page sees user as authenticated and redirects back
Root Cause:
The useSession() hook doesn't immediately update after signOut() due to client-side caching. Even with await refetch() after signOut, there's a timing issue where React state hasn't propagated to router context yet.
Thank you! If there's any solution, please help!
Better Auth with cookieCache enabled
TanStack Router
React with AuthProvider using authClient.useSession()
Node.js with Express for backend
Issue:
When user clicks logout:
authClient.signOut() succeeds (returns {success: true})
auth.isAuthenticated still returns true in React context
Navigation to /login fails - login page sees user as authenticated and redirects back
Root Cause:
The useSession() hook doesn't immediately update after signOut() due to client-side caching. Even with await refetch() after signOut, there's a timing issue where React state hasn't propagated to router context yet.
Thank you! If there's any solution, please help!