getAccessTokenSilently redirects to login when session has expired

We are trying to show an error message to the user when the session has expired.
We are referring this thread - https://community.auth0.com/t/check-session-without-extending-it/58569.
Our idea is to consume “login_required” error which comes from getAccessTokenSilently method.
We do get that “login_required” error message, but before we could handle it, the auth0 SDK is redirecting us to the login page.
Our expectation is that when error message arrives, we need to a custom modal intimating the user that the session has expired.

2 Likes

I’m also running into this.

It turns out that the HOC withAuthenticationRequired is always going to force the user to the login UI (and then perhaps the callback URL depending on the token expiration settings) when the auth0 session expires. This means that calling getAccessTokenSilently and getting an error about login_required will always result in the HOC withAuthenticationRequired ejecting the user to the login screen.

That also means that you won’t be able to do anything in the catch block of the getAccessTokenSilently because withAuthenticationRequired is handling it for you.

2 Likes