Open joseffsmith opened 1 year ago
hi @joseffsmith , thank you for your issue.
That a good enhancement to aad. whithout servieworker, I'am using https://github.com/AxaFrance/react-oidc/blob/master/packages/react/src/FetchUser.tsx that allow to make fetch always with valid token. to make token valid in tryKeepSession make sence.
Hi @guillaume-chervet, thanks for your response.
So you are using the fetch
to make sure the token is valid? That example requests userinfo
which doesn't have the token but I suppose you can use any endpoint?
I suppose that is similar to what I am doing here, checking the token is valid and renewing if it is not. It would be nice if the validity check in the library checked expiry instead of token presence.
If you agree with my comment and want to proceed with a similar approach please let me know if I can help in any way, I am happy to contribute
Hi @joseffsmith , yes it is very similar. It is because on some edge case. For example if your browser is sleeping and you come back to your website. You may have still old tokens and it requires few time to refresh it. Service worker do it internally as a proxy but whithout. Client js should wait for the synchronisation.
Issue and Steps to Reproduce
On page load the function
tryKeepExistingSessionAsync
checks that tokens exist, if they do then thetokens inside storage are valid
. This does not check the expiry so if the token is expired then it's not until after the first timeout (1 second) inautoRenewTokens
that the token is refreshed.you can see the initial events here
and then one second later
config, the key line is 'localStorage' I think, because if sessionStorage was used then there would be no token at all and the initial check would fail:
Versions
Screenshots
Expected
I would expect there to be an initial expiry check when kicking off the autoRenew
Actual
Additional Details
I am doing this to fix the issue