How to prevent api requests after 1st request fails with 401 response and re-execute only after refreshing token in angular

Viewed 25

Context: I have a Angular application with oAuth access_token authentication and guards protecting the routes which is working as expected. I have an auth interceptor which will catch the 401 Unauthorised status code and refresh the access_token with refresh_token.

Issue: When refreshing the access_token, the other two requests out of the three will also fail with 401 Unauthorised. Can we prevent api requests after 1st request fails with 401 response and re-execute only after refreshing access_token?

I tried pooling the request after the first 401 error, but the other two calls are not waiting for refresh_token api to finish.

Any suggestions or guidance would be appreciated.

Thanks! in advance

0 Answers
Related