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