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 -
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.


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.


Is there a reason why we cannot override this functionality? I would at least like to have options within the withAuthenticationRequired method that allows me to choose some kind of action. This is a problem for the flow I’m trying to create because this method is by far the easiest way to secure individual components, however, it also leads to an inability to prompt the user for a login instead of an automatic redirect that will re-use an active social login session.

I’m not sure how to use this library to achieve what Auth0 has on their own website! Their website is setup so that once per day, I have to re-authenticate with the site and it doesn’t reuse my active social login automatically. Instead, it still prompts me to login and I must select my social login each day. I don’t have to re-login to my social provider, but I do have to at least select it from the sign-in screen for Auth0.

So, if they can do this flow, why is it so difficult for me to do this flow using their library??