Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle refresh token and failed requests retry when access token expires #1899

Closed
ghost opened this issue Jul 24, 2019 · 7 comments
Closed

Comments

@ghost
Copy link

ghost commented Jul 24, 2019

I am trying to implement an OAuth authentication mechanism with refresh token and access token. I have searched for the solution a lot. But, still I haven't find any comprehensive solution that works for me.
I have different watchers for different actions. The main problem is when the access token expires. I want to have a solution for refreshing the token and more importantly re-try failed request with 401 code. What is the best solution for my case? I don't want to miss any failed request and want to retry them all.

@janhesters
Copy link

It would be cool to have an example in the docs for this.

@mattiassamskar
Copy link

+1

@ghost ghost closed this as completed Nov 25, 2019
@janhesters
Copy link

@hadiranjbar25 Could you please leave the issue open, even if you solved your problem? I think this is still a neat addition to the docs.

@ghost
Copy link
Author

ghost commented Nov 25, 2019

@janhesters I got that we should handle it in axios level, not in redux-saga.

@estebanx64
Copy link

@janhesters I got that we should handle it in axios level, not in redux-saga.

i tried with interceptor in axios, but when the API responses 401 and interceptor capture and handle that response, the yield in saga is launched and then entry in the catch exception, before of the interceptor complete the flow and renew token.

do you solved it?

@ghost
Copy link
Author

ghost commented Nov 26, 2019

Yes, that's because you are resolving it even if it is unauthorized. While you have not resolved it, saga waits for the response. This is a great tutorial I have used to implement it:
https://www.techynovice.com/setting-up-JWT-token-refresh-mechanism-with-axios/

@le-blip
Copy link

le-blip commented Nov 2, 2022

How to handle multiple requests after refresh? My interceptor makes the calls but my state is not updated because saga is resolving promise as error due to token expiry. How do i control my saga response for refresh?
Two questions:

  1. How to handle multiple requests after refresh correctly?
  2. How do i control my saga response if refreshing?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants