Closed NiallWalshRAM closed 4 weeks ago
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.
useEffect(() => {
const interval = setInterval(() => doAPICallRegulary(token))
return () => clearInterval(interval)
}, [token])
Could you please provide a full example of all involved functions and classes?
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, Niall
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 I can see the local storage is updated correctly with the new access_token If I interact with my application and click to a new tab, new button press etc etc, it will use the new access_token It just seems to happen when the application polls freely with no user interaction.
Steps To Reproduce
The current behavior
My expectation that after the access_token is refreshed, the AuthContext token will use the newest access_token if backend calls are polled.
The expected behavior
What currently happens is that after the access_token is refreshed, the AuthContext token uses the oldest access_token if backend calls are polled.