Help: New Access token isn't used after refresh token #192
-
My application polls my backend every X minutes using the bearer token. If I leave it sit and poll and the access_token naturally expires. Subsequent calls continue to use the expired token rather than use the new access_token that is retrieved using the refresh_token I can see the refresh token is used to get access_token
Steps To Reproduce
The current behaviorMy expectation that after the access_token is refreshed, the AuthContext token will use the newest access_token if backend calls are polled. The expected behaviorWhat currently happens is that after the access_token is refreshed, the AuthContext token uses the oldest access_token if backend calls are polled. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @NiallWalshRAM useEffect(() => {
const interval = setInterval(() => doAPICallRegulary(token))
return () => clearInterval(interval)
}, [token]) Could you please provide a full example of all involved functions and classes? |
Beta Was this translation helpful? Give feedback.
-
Hi @soofstad, Thank you for the added information above. After your feedback, I updated one of my setIntervals calls to updated everytime the token updates like above and I can confirm this resolves the issue I'm facing. Really appreciate the time you've spent to help me on this. BR, |
Beta Was this translation helpful? Give feedback.
Hi @NiallWalshRAM
I believe what is happening that the "setInterval" or similar you are using to regularly fetch "accounts" are not properly setup to reuse the new token value.
For example this code that replaces the "interval" function when any dependent variables update.
Could you please provide a full example of all involved functions and classes?