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 EmailPassword from "supertokens-auth-react/recipe/emailpassword";
SuperTokens.init({    appInfo: {        apiDomain: "...",        appName: "...",        websiteDomain: "...",    },    recipeList: [        EmailPassword.init({            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.

What type of UI do you want to use?
Custom UI
Pre built UI