Hooks and overrides
SuperTokens exposes a set of constructs that allow you to trigger different actions during the authentication lifecycle or to even fully customize the logic based on your use case.
The following sections describe how you can modify adjust the emailverification
recipe to your needs.
Explore the references pages for a more in depth guide on hooks and overrides.
Backend override
To perform any task post email verification like analytics, sending a user a welcome email or notifying an internal dashboard, you need to override the verifyEmailPOST
API.
import SuperTokens from 'supertokens-node';
import EmailVerification from "supertokens-node/recipe/emailverification";
import Session from "supertokens-node/recipe/session";
SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
EmailVerification.init({
mode: "REQUIRED",
override: {
apis: (originalImplementation) => {
return {
...originalImplementation,
verifyEmailPOST: async function (input) {
if (originalImplementation.verifyEmailPOST === undefined) {
throw Error("Should never come here");
}
// First we call the original implementation
let response = await originalImplementation.verifyEmailPOST(input);
// Then we check if it was successfully completed
if (response.status === "OK") {
let { recipeUserId, email } = response.user;
// TODO: post email verification logic
}
return response;
}
}
}
}
}),
Session.init()
]
});