okta-auth-js
okta-auth-js copied to clipboard
Okta Auth in PWA with offline access
Hi,
I am building progressive web app with okta authentication, we do have a requirement that user should be able to continue accessing application once authenticated and have access token even if the token is expired.
As per okta-auth-js default storage is browser local storage and token is persisted even user close browser and come back but once token is expired it auto-renewed but if user is offline i would like auto renewal to be paused and user to be able to continue using the application.
Currently I am getting blank page on my application when user is offline and okta trying to renew the token.
Here is the link to demo application - https://codesandbox.io/s/unruffled-hill-4g4i5
@brvaland I would recommend setting tokenManager.autoRenew
and tokenManager.autoRemove
to false
in the tokenManager options and then subscribing to the expired
event from the TokenManager. Your event handler can choose whether to renew the token immediately or defer for later.
@aarongranick-okta - thanks for your quick reply.
I did configure as per your suggestion and token renewal stopped and allows me to differ it later and able to renew token once user is back online. I have noticed an issue when user is offline, token is expired and then user click on browser refresh or F5 app is redirected to okta and browser throws network error.
Here is link reference to what i have implemented - https://codesandbox.io/s/unruffled-hill-4g4i5?file=/src/AppRouter.tsx
Please advise ?
@aarongranick-okta any update reference to the code example (link posted above).?
@brvaland I think the redirect to okta behavior is caused by the SecureRoute
(from okta-react), you can provide an onAuthRequired to customize the behavior.