axios-auth-refresh icon indicating copy to clipboard operation
axios-auth-refresh copied to clipboard

createAuthRefreshInterceptor is not a function

Open tomerh2001 opened this issue 11 months ago • 1 comments

import createAuthRefreshInterceptor from 'axios-auth-refresh';

const authToken = Buffer.from(`${aws.production!.outbrain.user}:${aws.production!.outbrain.password}`).toString('base64');
const fetchAccessToken = cachedFunction(OutbrainUtils.fetchAccessToken);

const client = axios.create({
	baseURL: `${aws.production!.outbrain.urlApi}${context.user!}`,
	timeout: moment.duration(10, 'second').asMilliseconds(),
});

const refreshAccessToken = async (failedRequest: AxiosError) => {
	await invalidateCache(fetchAccessToken, [authToken]);
	const accessToken = await fetchAccessToken(authToken) as CachedFunctionResult<Promise<string>>;
	failedRequest.config!.headers['OB-TOKEN-V1'] = await accessToken.result;
	return client.request(failedRequest.config!);
};

createAuthRefreshInterceptor(client, refreshAccessToken, {statusCodes: [StatusCodes.UNAUTHORIZED]});
client.interceptors.request.use(async request => {
	const accessToken = await fetchAccessToken(authToken) as CachedFunctionResult<Promise<string>>;
	request.headers['OB-TOKEN-V1'] = await accessToken.result;
	return request;
});
return client;

But I get ERROR: createAuthRefreshInterceptor is not a function.

This is the version in my package.json:

    "axios-auth-refresh": "^3.3.6",

What am I missing?

tomerh2001 avatar Nov 28 '24 08:11 tomerh2001