Skip to main content
Which UI do you use?
Custom UI
Pre built UI

Post sign in callbacks

1) On the frontend#

This method allows you to fire events immediately after a successful sign in. For example to send analytics events post sign in.

import SuperTokens from "supertokens-auth-react";
import EmailPassword from "supertokens-auth-react/recipe/emailpassword";
import Session from "supertokens-auth-react/recipe/session";

SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
EmailPassword.init({
onHandleEvent: async (context) => {
if (context.action === "SUCCESS") {
if (context.isNewRecipeUser && context.user.loginMethods.length === 1) {
// TODO: Sign up
} else {
// TODO: Sign in
}
}
}
}),
Session.init()
]
});
info

Please refer to this page to learn more about the onHandleEvent hook.

2) On the backend#

For this, you'll have to override the signIn recipe function in the init function call.

import SuperTokens from "supertokens-node";
import EmailPassword from "supertokens-node/recipe/emailpassword";
import Session from "supertokens-node/recipe/session";

SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
EmailPassword.init({
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
signIn: async function (input) {

// First we call the original implementation of signIn.
let response = await originalImplementation.signIn(input);

// Post sign up response, we check if it was successful
if (response.status === "OK") {
/**
*
* response.user contains the following info:
* - emails
* - id
* - timeJoined
* - tenantIds
* - phone numbers
* - third party login info
* - all the login methods associated with this user.
* - information about if the user's email is verified or not.
*
*/

// TODO: post sign in logic
}
return response;
}
}
}
}
}),
Session.init({ /* ... */ })
]
});
Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI