Repository navigation
fix(auth): log out on 401 responses - #190
Open
fernandatoledo wants to merge 3 commits into
Open
fernandatoledo wants to merge 3 commits into
fernandatoledo wants to merge 3 commits into
Conversation
Handle the 401 in the response interceptor's rejection handler, where Axios delivers non-2xx responses, and eject the provider's response interceptor on unmount instead of a request interceptor id. Fixes #185
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the changes to log users out on shared Axios client 401 responses.
No open issues 🎉
What changed in this PR
Overall Review: ai:clean
Fixes #185 by making the shared Axios client’s 401 responses log users out through AuthProvider.
Changes:
- Handles 401 errors in the rejection handler while preserving error propagation.
- Corrects response-interceptor cleanup and adds regression tests.
- Excludes local
.claude/runs/output from ESLint.
| File | Description |
|---|---|
src/components/providers/auth.tsx |
Fixes 401 logout handling and interceptor cleanup. |
eslint.config.mjs |
Ignores local agent run output. |
__tests__/components/providers/auth.test.tsx |
Tests response handling, session state, error propagation, and cleanup. |
Review effort: Balanced
amaury901130
approved these changes
Dec 3, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this do?
Fixes #185. A 401 response now logs the user out.
AuthProviderchecked for a 401 in the success handler of its response interceptor. Axios rejects non-2xx responses, so that check never ran. The 401 is now handled in the rejection handler, which callslogout()and still rethrows the error.client.interceptors.request.eject()with the id of a response interceptor, so the provider's interceptor was never removed. Every remount (StrictMode, Fast Refresh) stacked another copy, and with the 401 handling working each copy would calllogout(). It now ejects fromresponse.Why did you do this?
When the backend revokes a session (password change, logout from another device, server-side expiry) while the stored expiry is still in the future, the app kept treating the user as logged in:
isAuthenticatedstayed true and protected screens stayed reachable while their API calls failed. With #183, the stored session also decides whether a deep link opens a protected screen directly.Who/what does this impact?
Any 401 from the shared Axios
clientnow clears the session and sends the user to sign-in. A 401 from the sign-in endpoint (wrong credentials) also callslogout(), which is harmless since there is no session yet. Token refresh is still a TODO; this only covers logging out.Risk:
risk:high(auth).How did you test this?
New cases in
__tests__/components/providers/auth.test.tsx: a successful response refreshes auth state from storage and is returned unchanged; a 401 logs out and rethrows; a 500 and a non-Axios error keep the session and rethrow; unmount ejects the response interceptor (not a request one). The 401 and eject tests fail on the previous code.pnpm run type-check,pnpm run lintand the full Jest suite pass.Notes:
Also adds
.claude/runs/to the ESLint ignores, next to the existing.claude/worktrees/. Local agent run output there (Maestro YAML flows) madeeslint .fail, which blocked Pushgate's pre-push lint even though those files are not tracked.Follow-up, not changed here:
logout()clears the provider's MMKV storage and state but not the Zustand store insrc/lib/auth, whose tokensrc/api/common/interceptors.tskeeps attaching to requests. The Settings logout has the same gap.🤖 Generated with Claude Code