Skip to content

Auth UX: Implement automatic Login redirect on 401 Unauthorized API responses聽#303

Description

@Shevilll

馃攳 Problem Statement

When JWT tokens expire, API requests fail silently with 401 Unauthorized responses. Because there is currently no global handling for these responses, the frontend leaves the user in a broken UI state (e.g., empty dashboards, unresponsive action elements, or persistent loading states) without any feedback or session recovery.

馃専 Feature Description

We need to implement automatic and graceful handling of 401 responses on the frontend to improve the Auth UX. This can be achieved by adding a global Axios response interceptor that intercepts 401 Unauthorized errors from API requests.

馃幆 Proposed Solution & Implementation Details

  1. Axios Interceptor: Add/update a global Axios response interceptor that catches any response with a status code of 401.
  2. Clear Client-Side Credentials: Upon detecting a 401, clear all relevant auth storage (e.g., JWT tokens, user profiles from localStorage/sessionStorage or cookies) to reset the client session state.
  3. Automatic Redirect: Trigger a clean, router-based redirect to /login so the user can easily re-authenticate and restore their session.
  • I agree to follow this project's Code of Conduct

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions