axios-auth-refresh: refreshAuthLogic is not recalled on a second failure
Assume that you are making a request which returns a 401.
refreshAuthLogic will be called as it should and this second request is returning again a 401.
This second failure is not triggering refreshAuthLogic again, is this intentional?
Is there any way to re-trigger the callback?
My scenario goes as follows: A web application is utilizing the UMA flow which uses RPT Tokens to access resources. RPT tokens are cached and they may expire. On expiration a 401 is issued and I retry using a normal access token which will respond (again) with a 401 and a permission ticket which in turn will be exchanged for a new RPT token. So the scenario is request -> 401 -> request again -> 401 -> request again -> possibly 200
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 6
- Comments: 19 (3 by maintainers)
I had the same problem, and solution provided by @CteixeiraPW seems to work; In my code I made this change.
Before
After
I think it was because I set
pauseInstanceWhileRefreshingto true but if I remove it, the second request is sent with the old tokensame problem.
that’s the problem is.
Hello @Flyrell,
I have in my app an interceptor to add the token.
If I remember well, I think in your code you are intercepting every response with a 401 and the first one triggers the refreshing of the token and create an interceptor to bind all the following requests, but the problem is that by the time that you create this “createRequestQueueInterceptor” more that one request have already been sent.
This means you may have two or more responses with 401, the first one gets a retry with the new token but not the second one.
The first response will add the instance to the “skipInstances” list
But the “shouldInterceptError” will reject the second response with 401 because the instance is already in the “skipInstances” list.
This is why I think this error is happening. Please, let me know if any of my assumptions is wrong. I am not an expert in JS or React.
I was having the exact same problem. After checking the source code and understanding how it works, I did a few tests. On the first test, I have a function with 3 calls to my API using an expired token and same Axios instance. This first test showed that the execution for these request happened sequentially. This first test did not produce any error.
Then, I did a second test where I called the function three times. The first call to the function was executed in parallel with the execution of the second call and the third call.
Something like this.
This second test gave me the same errors like @israelKusayev (with pauseInstanceWhileRefreshing in true or false)
I am not an expert in JavaScript or Typescript. I think the responses are coming almost at the same time using the same Axios instance. Like using a different thread. The first response gets into the “refreshAuthLogic” and it creates the request interceptor that stalls any other request (when we have pauseInstanceWhileRefreshing in true). By the time when this happens, there are two more responses coming, and they will not execute the “refreshAuthLogic”.
I solved this situation adding an extra interceptor to resend those requests that where not handle by the “refreshAuthLogic” and that are not stalled by the request interceptor, to add them to the stalled requests.
Please let me know if you get same errors and if you have a better/cleaner solution.
here is my implemention
my refresh token is simple POST request with no special arguments
I also see only one request after refreshToken success I’m using axios-auth-refresh 3.0.0 and axios version 0.21.0