Show Popup/Alert Before Logging Out With GetAccesTokenSilently

Hi

SDK:- Latest REACT Auth0 SDK

In react, I’m storing access token in cookie. I want to update access token (grant_type
: “refresh_token”) after its expiry using getAccessTokenSilently.

And setup works fine until absolute lifetime of refresh token (refresh token rotation is enabled).

Once absolute lifetime of refresh token is over, getAccessTokenSilently logs out of application automatically.

But I want to show alert or warning before logging out user. How can I do that?

@dan.woda @lihua.zhang or anyone please help with it…

Regards
Rishi Tiwari

I’m using setup similer to this:- Implementing AutoLogout Feature in Web Applications (React-JS) - DEV Community 👩‍💻👨‍💻

Got the solution from another thread Check session without extending it. We can do like this:-

getAccessTokenSilently()
      .then((token) => {
        console.log(token);
      })
      .catch((e) => {
        if (e.error === "login_required")
          alert("logging out");
      });

Thanks :slight_smile:

2 Likes

Thanks for sharing it with the rest of community!

2 Likes