Skip to main content

Redirect the user to a specific route post login

By default, the user is redirected the the / route on your website post login. To change this, you can use the getRedirectionURL function on the frontend as shown below:

import SuperTokens from "supertokens-auth-react";import Passwordless from "supertokens-auth-react/recipe/passwordless";
SuperTokens.init({    appInfo: {        apiDomain: "...",        appName: "...",        websiteDomain: "...",    },    recipeList: [        Passwordless.init({            contactMethod: "EMAIL_OR_PHONE", // Other options: "EMAIL", "PHONE"            getRedirectionURL: async (context) => {                if (context.action === "SUCCESS") {                    if (context.redirectToPath !== undefined) {                        // we are navigating back to where the user was before they authenticated                        return context.redirectToPath;                    }                    return "/dashboard";                }                return undefined;            }        }),    ]});

The user will be redirected to the provided URL on:

  • Successful sign up
  • Successful sign in
  • Successful email verification.
  • If the user is already logged in.

Please refer to this page to learn more about the getRedirectionURL hook.