refreshing access token manually in axios
In my axios API calls, I need to give an Authorization header with the access token -
Question - How should I ideally be handling this refreshing of the access token?
What I am doing right now - Using a useAccessToken hook as follows -
Not at all sure if this is what the recommended way is (for example - using a library like jose or an equivalent to decode the jwt). Would really appreciate some confirmation before I make changes in all my tanstack query hooks!
3 Replies
When the accessToken expires, you're automatically refreshing the token without the user do anything?
The refresh (if expired) only happens when an API is being called.
Well, i don't know what
app.currentUser?.refreshCustomData()
does, but to me it seems that you're doing the validation on the client-side, but the validation should occur server-side. Your app should be able to automatically handle when the server responds with an "Token expired", to prompt the user(since there is a currentUser, i assume there is a user) to input the credentials again.
Right now, it seems that you're refreshing the token without the user pass the credentials again, so it's like an infinite session, unless refreshCustomData()
does something else