Skip to main content

Redirect To Auth Screen

Using the redirectToAuth function#

Use the redirectToAuth({show?: "signin" | "signup", redirectBack?: boolean}?) function to redirect the user to the full page auth screen provided by SuperTokens.

import React from "react";import { redirectToAuth } from "supertokens-auth-react/recipe/thirdpartyemailpassword";
function NavBar () {  async function onLogin () {    redirectToAuth();   }  return (    <ul>        <li>Home</li>        <li onClick={onLogin}>Login</li> 
    </ul>  )}
  • Call redirectToAuth({show: "signin"}) to take them to the sign in screen
  • Call redirectToAuth({show: "signup"}) to take them to the sign up screen
  • If you want the user to be redirected to the current page post sign in, use redirectToAuth({redirectBack: true})

Redirecting manually#

Alternatively, you can also redirect the user manually by setting window.location.href or using an SPA router like react-router-dom.

To show the sign in page on redirect, you want to add the query param ?show=signin to the URL. To show the sign up page on redirect, you want to add ?show=signup instead.

To make the user navigate back to where their current page, you should add the query param ?redirectToPath=/somepath