Skip to main content

Method 4) Custom method

This method allows you provide a callback using which you can send SMSs however you like. The input to the callback will be SMS template variables, so you can freely create the content of the SMS as well. Use this method if you are:

  • Using a third party SMS service that is not Twilio.
  • You want to use another delivery methog like Whatsapp or FB Messenger.
  • You want to do some custom spam protection before sending the SMS.
  • You already have an SMS sending infrastructure and want to use that.
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 ({
codeLifetime, // amount of time the code is alive for (in MS)
phoneNumber,
urlWithLinkCode, // magic link
userInputCode, // OTP
}) {
// TODO: create and send SMS
}
}
}
},
}),
Session.init()
]
});

If you call the original implementation function for sendSms, it will use the service that you have configured. If you have not configured any service, it will use the default service.

important

When using this callback, you must manage sending the SMS yourself.

Which frontend SDK do you use?
supertokens-web-js / mobile
supertokens-auth-react