-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Question: axios in React lifecycle #110
Comments
Maybe putting axios and the interceptors in a React context? Like it is done in this article? Here are also some suggestions: axios/axios#2315 |
Hey @s1gr1d , I am curious, why do you need React to track your tokens? If the token needs to be refreshed, that should be done in the background without involving React in the process. For that, you can try https://github.com/Flyrell/axios-auth-refresh which allows refreshing tokens within interceptors. |
@alan2207 what about auth0 where you have a hook called So in that case I need axios to be inside the react context to being able to inject the token into an interceptor. In our case we use something like this:
|
Well it depends on how you get token and store in the browser. |
I love your project and have been using it for a while to look for examples. I've just been wondering how the axios instance and interceptors work with React in the way they are implemented now.
I suppose the instance is created once you reload the page and then it gets the token from the store. But what if there is no token at that time? What happens when the token changes during usage of the application? I implemented the axios instance according to bulletproof-react in one of my projects and have the issue that the axios instance is not refreshed after the user logs in (token change).
How does the example work here? Or do we need to put the axios instance in a React hook which can change the values?
Thanks in advance for some clarity 🙏
The text was updated successfully, but these errors were encountered: