Skip to main content

Handling session expiry

note

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#

When you use ThirdPartyEmailPasswordAuth to provide SessionContext to your components, you can a pass function to onSessionExpired prop. This function will be called when the session expires.

import React from "react";import { ThirdPartyEmailPasswordAuth } from "supertokens-auth-react/recipe/thirdpartyemailpassword";import MyComponent from "./myComponent";
const App = () => {    return (        <ThirdPartyEmailPasswordAuth            requireAuth={true}            onSessionExpired={() => {/* ... */ }}>            <MyComponent />        </ThirdPartyEmailPasswordAuth>    );}
important

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