The request does not return to its original promise and instance is not paused until refresh is complete
See original GitHub issueI was using this library with its previous versions (worked great by the way š ) but I decided to update axiosās and its version because I was facing other problems. But now there is the problem that failed request due to 401 or 403 does not return to its original promise it just fires again and resolves.
Here is my logic for calling apis:
const refreshAuthLogic = (failedRequest) =>
axios
.post(`${process.env.API_BASE_URL}user/refresh/`, getFormData())
.then((tokenRefreshResponse) => {
console.log(tokenRefreshResponse.data.refresh_token)
Cookies.set('token', tokenRefreshResponse.data.access_token, {
expires: 1 / 24
})
Cookies.set('refreshToken', tokenRefreshResponse.data.refresh_token, {
expires: 365
})
failedRequest.response.config.headers.Authorization = `Bearer ${
tokenRefreshResponse.data.access_token
}`
return Promise.resolve()
})
.catch((error) => {
// if(Cookies.get('refreshToken') == undefined && Cookies.get('token')) {
Auth.signout()
window.location.reload(false)
// }
})
const instance = axios.create({
baseURL: process.env.API_BASE_URL
})
instance.interceptors.request.use((request) => {
request.headers.Authorization = `Bearer ${Cookies.get('token')}`
return request
})
createAuthRefreshInterceptor(instance, refreshAuthLogic, {
statusCodes: [401, 403],
pauseInstanceWhileRefreshing: true
})
export default instance
and I use the instance like:
const settingsPromise = API.get('user/settings/', {
headers: { Authorization: `Bearer ${Cookies.get('token')}` }
})
const userDataPromise = API.get('user/profile/', {
headers: { Authorization: `Bearer ${Cookies.get('token')}` }
})
Promise.all([settingsPromise, userDataPromise]).then((result) => {
// other code
})
and sometimes:
API.get('user/settings/', {
headers: { Authorization: `Bearer ${Cookies.get('token')}` }
}).then((result) => {
// other code
})
but for these calls it does not return to promise.
Also the instance is not paused until refresh is complete, even after refresh is called more requests are made and they also return 401 or 403 and there is another refresh call.
axios@0.21.1 axios-auth-refresh@3.1.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Wait until all promises complete even if some rejected
I was searching hard for Promise.all not even first reject but didn't know to search "Reflect". Should ES6 have a Promise.reflect which is...
Read more >Node.js v19.3.0 Documentation
If the function does not return a promise, assert.doesNotReject() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the errorĀ ......
Read more >API Reference - Tableau Help
Represents a promise to return a value from an asynchronous method in the future. ... The permissions on a workbook or a view...
Read more >Refresh an external data connection in Excel - Microsoft Support
You can connect your Excel workbook to an external data source, such as a SQL Server database, an OLAP cube, or even another...
Read more >Frequently Asked Questions | Republic Services
Through our subsidiaries, we provide recycling and non-hazardous solid waste ... By default, your auto pay will pay the full balance of your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Iām also getting the same issue. Though I happened to come across a fairly simple workaround:
before:
after (see
I tried what you said @Flyrell, it returns to the original promise now but the refresh logic is being run twice for three consecutive api calls. Also, I donāt think I need skipAuthRefresh flag because I actually donāt use the instance to call the api in refresh logic. I tried using instance in the refresh logic with skipAuthRefresh and that also didnāt work.
I changed my code a bit so here it is for reference:
Create auth func:
Example request scenario: