React SPA - Automatically Redirect to Login Page When Access Token Expires

  • Which SDK this is regarding: e.g. auth0-react

Hi, we have auth0 up and running for a React SPA + Node Backend. We have a 4 hour inactivity timeout enabled in Auth0, which works fine.

The issue we’re trying to mitigate is: a user logged in, used the application for a bit. They switch tabs, leave their desk, etc., and 4 hours later, they revisit the application.

When they perform an action that requests an auth0 access token (e.g. try to view protected content in the app, or submit data), they get redirected because we have a .catch() function running in the event their getAccessTokenSilently request fails, which redirects them to the login screen.

What we’d like to do is automatically redirect them to the login screen as soon as their inactivity timeout window hits — so that they don’t have to attempt to take actions in the app only to get kicked back to the login screen.

Is there a best practice to achieve this that we should be following?

1 Like