Which UI do you use?
Custom UI
Pre built UI
Handle Event Hook
This function is called for various user actions. It can be used for logging, analytics or any side effect purposes (these are essentially fire and forget events).
- 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).supertokensUIEmailPassword.init({
onHandleEvent: (context) => {
if (context.action === "PASSWORD_RESET_SUCCESSFUL") {
} else if (context.action === "RESET_PASSWORD_EMAIL_SENT") {
} else if (context.action === "SUCCESS") {
if (context.createdNewSession) {
let user = context.user;
if (context.isNewRecipeUser && context.user.loginMethods.length === 1) {
// sign up success
} else {
// sign in success
}
} else {
// this is during second factor login of step up auth flow
}
}
}
})
import EmailPassword from "supertokens-auth-react/recipe/emailpassword";
EmailPassword.init({
onHandleEvent: (context) => {
if (context.action === "PASSWORD_RESET_SUCCESSFUL") {
} else if (context.action === "RESET_PASSWORD_EMAIL_SENT") {
} else if (context.action === "SUCCESS") {
if (context.createdNewSession) {
let user = context.user;
if (context.isNewRecipeUser && context.user.loginMethods.length === 1) {
// sign up success
} else {
// sign in success
}
} else {
// this is during second factor login of step up auth flow
}
}
}
})
// this goes in the auth route config of your frontend app (once the pre built UI script has been loaded)
(window as any).supertokensUIEmailPassword.init({
onHandleEvent: (context) => {
if (context.action === "PASSWORD_RESET_SUCCESSFUL") {
} else if (context.action === "RESET_PASSWORD_EMAIL_SENT") {
} else if (context.action === "SUCCESS") {
if (context.createdNewSession) {
let user = context.user;
if (context.isNewRecipeUser && context.user.loginMethods.length === 1) {
// sign up success
} else {
// sign in success
}
} else {
// this is during second factor login of step up auth flow
}
}
}
})
info
Also checkout the session recipe handle event hook.