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
{{ message }}
Repository navigation
Expired or logged-out sessions keep sending the old token from the Zustand auth store #188
The two auth layers don't clear together. AuthProvider (auth.tsx) keeps its session in authStorage, and the Zustand store (lib/auth/index.tsx) keeps its own copy of the token in the general MMKV storage. Nothing that ends the session in AuthProvider touches the Zustand store:
Expiry: the AuthProvider request interceptor calls clearTokens() (auth.tsx#L65) and checkToken sets token to null, but the Zustand token stays set.
Logout: logout() (auth.tsx#L139-L141), used by Settings, only calls clearTokens(). signOut() from the Zustand store is never called anywhere in src/.
The request interceptor in interceptors.ts#L19 attaches whatever useAuth.getState().token holds (Authorization, access-token, client, uid, expiry) without checking it. It is registered after the AuthProvider interceptor, and Axios runs request interceptors in reverse order, so it runs first, before AuthProvider gets a chance to clear anything. On the next launch, hydrateAuth() (_layout.tsx#L29) restores the same token from storage.
Impact
After the session expires or the user logs out, the UI shows them as logged out, but every API request still carries the old credentials, including across app restarts. A user who logs out on a shared device keeps sending their access-token/client/uid until another login overwrites them. Against a backend that still accepts the token, requests made "logged out" are made as the previous user.
Fix
Keep the dual-layer design and make authStorage the single source of truth for whether a session is valid:
Clear the Zustand store wherever AuthProvider ends the session (expiry, logout(), 401), e.g. by calling signOut() from one clearing path.
Don't let hydrateAuth() restore a token when there is no valid session.
No token refresh. Add Jest tests that, after expiry and after logout, neither interceptor sends the old token and hydrateAuth() leaves the store empty.
Builds on #183 (getValidAccessToken(), syncSession()). Related: #185.
Activity