Skip to main content

Redirection Callback Hook

This function is used to change where the user is redirected to post certain actions. For example, you can use this to redirect a user to a specific URL post sign in / up.

import Passwordless from "supertokens-auth-react/recipe/passwordless";

Passwordless.init({
contactMethod: "EMAIL", // This example will work with any contactMethod.
getRedirectionURL: async (context) => {
if (context.action === "SUCCESS") {
// called on a successful sign in / up. Where should the user go next?
let redirectToPath = context.redirectToPath;
if (redirectToPath !== undefined) {
// we are navigating back to where the user was before they authenticated
return redirectToPath;
}
if (context.isNewRecipeUser && context.user.loginMethods.length === 1) {
// user signed up
return "/onboarding"
} else {
// user signed in
return "/dashboard"
}
}
// return undefined to let the default behaviour play out
return undefined;
}
});
Looking for older version of the documentation?
Which UI do you use?
Custom UI
Pre built UI