Skip to main content

Handling session expiry

important

This feature is only applicable if you are using our pre built UI, and are using the <SessionAuth> component to protect your routes.

A session can expire if:

  • The user has been inactive for too long and their refresh token has expired.
  • The session has been revoked from the backend, but not the frontend.

Using the onSessionExpired prop#

import React from "react";
import { SessionAuth } from "supertokens-auth-react/recipe/session";
import MyComponent from "./myComponent";

const App = () => {
return (
<SessionAuth
onSessionExpired={() => {/* ... */ }}>
<MyComponent />
</SessionAuth>
);
}

You will need to either reload the current page or redirect the user to the sign in page if you provide this callback.

Which UI do you use?
Custom UI
Pre built UI