Axios plugin for automatic token refresh via request interceptors. Current stable version 5.0.2, actively maintained. Key differentiator: it stalls concurrent requests during token refresh and resolves them once a new token is available, preventing duplicate refresh calls. Requires axios >= 1.0.0 as a peer dependency. Ships TypeScript definitions. The library itself is lightweight (~1.2kB minified) and only intercepts 401 status codes by default, but allows custom status codes via options.
npm install axios-auth-refreshNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up automatic token refresh on 401 errors: interceptor calls refreshAuthLogic, updates Authorization header, and retries the original request.
Ensure the function returns a promise: const refreshAuthLogic = async (failedRequest) => { await refresh(); };Upgrade axios to 1.x or stay on axios-auth-refresh v4.x if using axios 0.x.
Use: createAuthRefresh(axios, refreshAuthLogic, { statusCodes: [401, 403] });Replace { interceptNetworkError: true } with { shouldRefresh: (error) => !error.response }Import AxiosAuthRefreshRequestConfig and use: axios.get('/url', { skipAuthRefresh: true } as AxiosAuthRefreshRequestConfig);Replace 'import createAuthRefresh from "axios-auth-refresh";' with 'import { createAuthRefresh } from "axios-auth-refresh";'Check if failedRequest.response exists before accessing config, or use the shouldRefresh option to avoid network errors.
Ensure the axios instance is created before calling createAuthRefresh: const axiosInstance = axios.create(); createAuthRefresh(axiosInstance, ...);