Skip to content

401 responses never log the user out #185

Backlog

Description

@fernandatoledo

Problem

AuthProvider checks for a 401 inside the success handler of its response interceptor (auth.tsx#L151-L160):

client.interceptors.response.use(
  (config) => {
    if (config.status === unauthorizedHttpStatusCode) {
      logout();
    }
    ...

Axios rejects non-2xx responses by default, so a 401 goes to the rejection handler (which only rethrows) and logout() never runs.

Impact

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 keeps treating the user as logged in: isAuthenticated stays true, protected screens stay reachable, and their API calls keep failing instead of sending the user to sign-in. With #183, the stored session also decides whether a deep link opens a protected screen directly, so the stale session reaches deep links too.

Fix

Handle the 401 in the rejection handler and rethrow:

(error: unknown) => {
  if (isAxiosError(error) && error.response?.status === unauthorizedHttpStatusCode) {
    logout();
  }
  throw error;
},

Add a test that a 401 response logs the user out. Note the token refresh TODO in the same file: this only covers logging out, not refreshing.

Found while reviewing #183.

Activity

  1. added
    bug
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions