Skip to main content

Pre / Post Hooks / Override

We provide you funtionality to run code before and after an email is sent. You can use this for:

  • Logging purposes
  • Spam protection purposes
  • Modifying the email template variables before sending the emails
import supertokens from "supertokens-node";
import EmailPassword from "supertokens-node/recipe/emailpassword";
import Session from "supertokens-node/recipe/session";
import EmailVerification from "supertokens-node/recipe/emailverification"

supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
EmailPassword.init({

emailDelivery: {
override: (originalImplementation) => {
return {
...originalImplementation,
sendEmail: async function (input) {
// TODO: run some logic before sending the email

await originalImplementation.sendEmail(input);

// TODO: run some logic post sending the email
}
}
}
},
}),

// if email verification is enabled
EmailVerification.init({
emailDelivery: {
override: (originalImplementation) => {
return {
...originalImplementation,
sendEmail: async function (input) {
// TODO: run some logic before sending the email

await originalImplementation.sendEmail(input);

// TODO: run some logic post sending the email
}
}
}
},
}),
Session.init()
]
});
Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI