Skip to content

[Frontend] Create Axios API Client with JWT Refresh InterceptorΒ #446

@yusuftomilola

Description

@yusuftomilola

A configured Axios instance that automatically attaches the JWT Bearer token to every request and handles 401 errors gracefully.

Requirements

  • Base URL set to http://localhost:6003/api (configurable via env)
  • Request interceptor: reads token from localStorage and adds Authorization: Bearer <token> header
  • Response interceptor: on 401, attempt POST /api/auth/refresh β†’ store new access token β†’ retry original request once. If refresh fails, call useAuthStore.getState().logout().
  • Export this as the default apiClient
  • Separate authApiClient (no interceptors) for login/register/refresh calls to avoid circular refresh loops

Acceptance Criteria

  • All API calls use the Axios instance (not plain fetch)
  • 401 triggers one refresh attempt before logout
  • Token automatically attached without manual headers per call

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions