Skip to main content

If you are using our backend SDK that is lesser than the following versions, please visit the older documentation link here.

Handling session expiry


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 (
onSessionExpired={() => {/* ... */ }}>
<MyComponent />

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

Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI