Registry /
security / axios-auth-refresh-queue
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
applyAuthTokenInterceptor
✓ import { applyAuthTokenInterceptor } from 'axios-auth-refresh-queue'
✗ import applyAuthTokenInterceptor from 'axios-auth-refresh-queue'
This is a named export, not default. TypeScript users should use the named import.
AuthTokenInterceptorOptions
✓ import { applyAuthTokenInterceptor } from 'axios-auth-refresh-queue'; import type { AuthTokenInterceptorOptions } from 'axios-auth-refresh-queue'
✗ import { AuthTokenInterceptorOptions } from 'axios-auth-refresh-queue' (if used at runtime)
If using TypeScript, import the type separately with `import type` to avoid runtime issues. The package exports types for the options.
axios instance
✓ const api = axios.create({ baseURL: '...' }); applyAuthTokenInterceptor(api, options)
✗ applyAuthTokenInterceptor({ baseURL: '...' }, options) (passing config object instead of instance)
The interceptor expects an Axios instance, not a config object. Create one with axios.create() first.
Shows complete setup: create Axios instance, apply interceptor with token handlers, and use the instance.
import axios from 'axios';
import { applyAuthTokenInterceptor } from 'axios-auth-refresh-queue';
const apiClient = axios.create({
baseURL: process.env.API_URL ?? 'https://api.example.com',
});
applyAuthTokenInterceptor(apiClient, {
headerTokenHandler: (request) => {
const token = localStorage.getItem('accessToken');
if (token) {
request.headers.Authorization = `Bearer ${token}`;
}
},
getRefreshToken: () => localStorage.getItem('refreshToken') ?? '',
requestRefresh: async (refreshToken: string) => {
const response = await axios.post('https://api.example.com/auth/refresh', {
token: refreshToken,
});
return {
accessToken: response.data.accessToken,
refreshToken: response.data.refreshToken ?? refreshToken,
};
},
onSuccess: (newTokens) => {
localStorage.setItem('accessToken', newTokens.accessToken);
if (newTokens.refreshToken) {
localStorage.setItem('refreshToken', newTokens.refreshToken);
}
},
});
// Usage:
apiClient.get('/data').then(response => console.log(response.data));
Errors
Common errors & fixes
Cannot read property 'interceptors' of undefined
Passing an Axios config object instead of an Axios instance to applyAuthTokenInterceptor.
fixCreate an Axios instance with axios.create() and pass that instance.
TypeError: request.headers is undefined
The Axios instance wasn't created with axios.create() or the request object is malformed.
fixEnsure you passed the Axios instance (not a config object) and that the instance is properly created.
Error: requestRefresh must return an object with accessToken property
The requestRefresh function returned a value that doesn't include accessToken.
fixReturn { accessToken: '...' } from requestRefresh. Audit
Dependencies
axiosrequiredpeer dependency; required at runtime