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

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