You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using this library to pause requests that fail with a 401 and attempt to refresh a token when these requests fail. My use also involves attaching request and response interceptors.
Here' the code I'm working with -
constaxiosInstance=axios.create({baseURL: HOST});constcreateAuthRefreshLogic=failedRequest=>axiosInstance.post('/auth/public/login',{},{skipAuthRefresh: true,headers: {'Content-Type': 'application/json',Authorization: `Basic ${btoa(`${CLIENT_ID}:${CLIENT_SECRET}`)}`},}).then((result)=>{console.log('createAuthRefreshLogic');failedRequest.response.config.headers.Authorization=`Bearer ${result.data.token}`;returnPromise.resolve();});axiosInstance.interceptors.request.use((config)=>{constlatestToken=AuthService.getAuthServiceInstance().getAuthToken();console.log('request interceptor');if(config.url==='/auth/public/login'){// eslint-disable-next-line no-param-reassignconfig.headers.Authorization=`Basic ${btoa(`${CLIENT_ID}:${CLIENT_SECRET}`)}`;}else{// eslint-disable-next-line no-param-reassignconfig.headers.Authorization=`Bearer ${latestToken}`;}returnconfig;});axiosInstance.interceptors.response.use((response)=>{console.log('response interceptor');GlobalService.getGlobalServiceInstance().setLastUpdatedAt(Date.now());returnresponse;},// Attempting to handle the errors here does not seem to work(error)=>thrownewApiError(error)// This causes the the createAuthRefreshLogic to not be invoked);
From the approach above, the requests don't seem to get paused for some reason? Is there an issue with how I'm approaching it.
If I uncomment the request and response interceptors, the createAuthRefreshLogic interceptor does not get invoked. Anything I'm doing wrong?
Update
I was able to get a part of the request and response interceptors to work with the createAuthRefreshLogic function.
However, trying to handle the errors within the response interceptor causes createAuthRefreshLogic to not be invoked, but I still see two 401 requests while neither seem to be paused.
Here's a screen shot of the network requests failing. The 401s don't seem to be getting paused.
The text was updated successfully, but these errors were encountered:
I am having the same issue here. When having two simultaneous request with pauseInstanceWhileRefreshing: true receiving 401 only the one who pass through the createAuthRefreshLogic interceptor is retrying. Any idea ? :D Thanks !
I am using this library to pause requests that fail with a 401 and attempt to refresh a token when these requests fail. My use also involves attaching
request
andresponse
interceptors.Here' the code I'm working with -
From the approach above, the requests don't seem to get paused for some reason? Is there an issue with how I'm approaching it.
If I uncomment the request and response interceptors, thecreateAuthRefreshLogic
interceptor does not get invoked. Anything I'm doing wrong?Update
I was able to get a part of the request and response interceptors to work with the createAuthRefreshLogic function.
However, trying to handle the errors within the response interceptor causes
createAuthRefreshLogic
to not be invoked, but I still see two 401 requests while neither seem to be paused.Here's a screen shot of the network requests failing. The 401s don't seem to be getting paused.
The text was updated successfully, but these errors were encountered: