Pre / Post Hooks / Override
We provide you funtionality to run code before and after an SMS is sent. You can use this for:
- Logging purposes
- Spam protection purposes
- Modifying the SMS template variables before sending the SMS
- NodeJS
- GoLang
- Python
import supertokens from "supertokens-node";
import Passwordless from "supertokens-node/recipe/passwordless";
import Session from "supertokens-node/recipe/session";
supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
Passwordless.init({
smsDelivery: {
override: (originalImplementation) => {
return {
...originalImplementation,
sendSms: async function (input) {
// TODO: before sending SMS
await originalImplementation.sendSms(input)
// TODO: after sending SMS
}
}
}
},
}),
Session.init()
]
});
import (
"github.com/supertokens/supertokens-golang/ingredients/smsdelivery"
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
passwordless.Init(plessmodels.TypeInput{
SmsDelivery: &smsdelivery.TypeInput{
Override: func(originalImplementation smsdelivery.SmsDeliveryInterface) smsdelivery.SmsDeliveryInterface {
originalSendSms := *originalImplementation.SendSms
(*originalImplementation.SendSms) = func(input smsdelivery.SmsType, userContext supertokens.UserContext) error {
// TODO: before sending SMS
err := originalSendSms(input, userContext)
if err != nil {
return err
}
// TODO: after sending SMS
return nil
}
return originalImplementation
},
},
}),
},
})
}
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe.passwordless.types import SMSDeliveryOverrideInput, SMSTemplateVars
from supertokens_python.recipe import passwordless
from typing import Dict, Any
from supertokens_python.ingredients.smsdelivery.types import SMSDeliveryConfig
def custom_sms_deliver(original_implementation: SMSDeliveryOverrideInput) -> SMSDeliveryOverrideInput:
original_send_sms = original_implementation.send_sms
async def send_sms(template_vars: SMSTemplateVars, user_context: Dict[str, Any]) -> None:
# TODO: before sending SMS
await original_send_sms(template_vars, user_context)
# TODO: after sending SMS
original_implementation.send_sms = send_sms
return original_implementation
init(
app_info=InputAppInfo(
api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
passwordless.init(
sms_delivery=SMSDeliveryConfig(override=custom_sms_deliver)
)
]
)