Which UI do you use?
Custom UI
Pre built UI
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. If you're embedding the sign in / up components in a popup and wish to disable redirection entirely, simply return null
.
- ReactJS
- Angular
- Vue
// this goes in the auth route config of your frontend app (once the pre built UI script has been loaded)
(window as any).supertokensUIInit("supertokensui", {
appInfo: {
appName: "SuperTokens",
apiDomain: "http://localhost:3000",
websiteDomain: "http://localhost:3000",
},
getRedirectionURL: async (context) => {
if (context.action === "SUCCESS" && context.newSessionCreated) {
// 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.createdNewUser) {
// user signed up
return "/onboarding"
} else {
// user signed in
return "/dashboard"
}
}
// return undefined to let the default behaviour play out
return undefined;
},
recipeList: [
(window as any).supertokensUIThirdParty.init(/* ... */)
]
})
import ThirdParty from "supertokens-auth-react/recipe/thirdparty";
import SuperTokens from "supertokens-auth-react"
SuperTokens.init({
appInfo: {
appName: "SuperTokens",
apiDomain: "http://localhost:3000",
websiteDomain: "http://localhost:3000",
},
getRedirectionURL: async (context) => {
if (context.action === "SUCCESS" && context.newSessionCreated) {
// 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.createdNewUser) {
// user signed up
return "/onboarding"
} else {
// user signed in
return "/dashboard"
}
}
// return undefined to let the default behaviour play out
return undefined;
},
recipeList: [
ThirdParty.init(/* ... */)
]
})
// this goes in the auth route config of your frontend app (once the pre built UI script has been loaded)
(window as any).supertokensUIInit("supertokensui", {
appInfo: {
appName: "SuperTokens",
apiDomain: "http://localhost:3000",
websiteDomain: "http://localhost:3000",
},
getRedirectionURL: async (context) => {
if (context.action === "SUCCESS" && context.newSessionCreated) {
// 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.createdNewUser) {
// user signed up
return "/onboarding"
} else {
// user signed in
return "/dashboard"
}
}
// return undefined to let the default behaviour play out
return undefined;
},
recipeList: [
(window as any).supertokensUIThirdParty.init(/* ... */)
]
})