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 ThirdPartyEmailPassword from "supertokens-node/recipe/thirdpartyemailpassword";
import Session from "supertokens-node/recipe/session";
import EmailVerification from "supertokens-node/recipe/emailverification"

supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
ThirdPartyEmailPassword.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 version of the documentation?
Which UI do you use?
Custom UI
Pre built UI