Still have problems with multiple request
See original GitHub issueHi I have problem with my multiple requests. Only the first 401 error probably getting new access token, second not.
Here is my code. `import axios from “axios”; import createAuthRefreshInterceptor from “axios-auth-refresh”;
const baseUrl = “https://****.com/”; const instance = axios.create({ baseURL: baseUrl, });
// Function that will be called to refresh authorization const refreshAuthLogic = (failedRequest: any) => axios .post(“https://****/api/token/refresh/”, { refresh: localStorage.getItem(“refreshToken”), }) .then((tokenRefreshResponse) => { localStorage.removeItem(“accessToken”); localStorage.setItem(“accessToken”, tokenRefreshResponse.data.access);
console.log(tokenRefreshResponse.data.access);
failedRequest.response.config.headers["Authorization"] =
"Bearer " + tokenRefreshResponse.data.access;
return Promise.resolve();
});
createAuthRefreshInterceptor(instance, refreshAuthLogic);
export default instance;` No matter if I set the newest options like skipWhileRefreshing, pauseInstanceWhileRefreshing - situation is the same. I tried previous closed issues but didnt work 😦
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Well, it’s probably because you mix
instance
andaxios
like it’s the same thing. Try to useinstance
after it’s created and it will work just fine 🙂So the final code would be:
You need put the logic for set auth token on an axios interceptor as the example on documentation:
previusly you define the function getAccessToken for example on localStorage.