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
- Plain JavaScript
- React Native
Note
You can use the
You can refer to this example app as a reference for using the
supertokens-web-js
SDK which exposes several helper functions that query the APIs exposed by the SuperTokens backend SDK.You can refer to this example app as a reference for using the
supertokens-web-js
SDK.Note
To use SuperTokens with React Native you need to use the
To add login functionality, you need to build your own UI and call the APIs exposed by the backend SDKs. You can find the API spec here
supertokens-react-native
SDK. The SDK provides session management features.To add login functionality, you need to build your own UI and call the APIs exposed by the backend SDKs. You can find the API spec here
What type of UI are you using?
Prebuilt UICustom UI
What type of UI are you using?
Prebuilt UICustom UI
import EmailPassword from "supertokens-auth-react/recipe/emailpassword";
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 === "TO_AUTH") {
// This is called when we want to navigate to the login page.
// By default, this will go to the configured websiteBasePath (/auth)
} else if (context.action === "SUCCESS" && context.newSessionCreated) {
// This is called when the user has successfully signed in / signed up.
// By default, this will go to "/" or to
// the redirectToPath if it is set (the page from which the user was redirected to the auth page).
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: [
EmailPassword.init({
getRedirectionURL: async (context) => {
if (context.action === "RESET_PASSWORD") {
// called when the user clicked on the forgot password button
}
// return undefined to let the default behaviour play out
return undefined;
}
})
]
});