Prompt
refresh token expired login loop
Latest observation
Nov 1, 2026
OpenAI APIWeb search: off
A refresh token expired login loop usually means your app keeps trying to silently re-authenticate, but the refresh token is no longer valid, so it keeps bouncing the user back to login.
Common causes
- Refresh token TTL is too short or already revoked
- Access token expired and refresh flow fails
- Cookie/session storage not persisted correctly
- Clock skew between client/server causing premature expiry
- Infinite retry logic: app retries refresh, fails, redirects to login, then immediately retries again
- Multiple tabs / devices invalidating the token
- Logout/rotation logic invalidates the old refresh token unexpectedly
How to fix
-
Detect refresh failure explicitly
- If refresh returns
401/invalid_grant/expired, stop retrying. - Clear auth state and send user to login once.
- If refresh returns
-
Prevent infinite redirects
- Add a guard so login redirects happen only once per failed session.
- Example: set a flag like
refreshFailed=true.
-
Use refresh token rotation correctly
- If you rotate refresh tokens, always replace the stored token with the new one immediately.
- Don’t reuse an old refresh token after refresh.
-
Check storage/cookie issues
- If using cookies, ensure:
HttpOnly,Secure,SameSiteare set appropriately- domain/path match your app
- If using localStorage/sessionStorage, verify it isn’t being cleared unexpectedly.
- If using cookies, ensure:
-
Make sure backend expiry settings align
- Refresh token lifetime should be long enough for your UX.
- Access token should be short-lived, refresh token longer-lived.
-
Handle clock skew
- Allow a small leeway when checking expiry timestamps.
Example logic
- API request gets
401 - App tries refresh once
- If refresh succeeds → retry original request
- If refresh fails → clear auth, redirect to login, stop retrying
Quick debug checklist
- Does refresh endpoint return
invalid_grant? - Is the refresh token being replaced after rotation?
- Is the stored refresh token current?
- Are you redirecting to login inside a request interceptor without a guard?
- Is a second tab invalidating the token?
If you want, I can help you diagnose this in a specific stack (React, Next.js, Angular, Spring, Node, Firebase, Auth0, Keycloak, etc.) or show a safe refresh flow example.