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
- Other Frameworks
Important
For other backend frameworks, you can follow our guide on how to spin up a separate server configured with the SuperTokens backend SDK to authenticate requests and issue session tokens.
import supertokens from "supertokens-node";
import ThirdPartyPasswordless from "supertokens-node/recipe/thirdpartypasswordless";
import Session from "supertokens-node/recipe/session";
supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
ThirdPartyPasswordless.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/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
thirdpartypasswordless.Init(tplmodels.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.thirdpartypasswordless.types import SMSDeliveryOverrideInput, SMSTemplateVars
from supertokens_python.recipe import thirdpartypasswordless
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=[
thirdpartypasswordless.init(
sms_delivery=SMSDeliveryConfig(override=custom_sms_deliver)
)
]
)