Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createAuthRefreshInterceptor is not a function #290

Open
tomerh2001 opened this issue Nov 28, 2024 · 1 comment
Open

createAuthRefreshInterceptor is not a function #290

tomerh2001 opened this issue Nov 28, 2024 · 1 comment

Comments

@tomerh2001
Copy link

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
Copy link
Author

tomerh2001 commented Nov 28, 2024

It works if I do

createAuthRefreshInterceptor.default(client, refreshAccessToken, {statusCodes: [StatusCodes.UNAUTHORIZED]});

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant