简体   繁体   中英

Phone authentication using Twilio Nodejs

I'm trying to use twilio to send SMS for OTP authentication using nodejs and I'm getting an error. Kindly, can somebody help me debug it. Below is my code to send the OTP SMS.

require('dotenv').config()
const twilio = require("twilio")(process.env.TWILIO_ACCOUT_SID, process.env.TWILIO_AUTH_TOKEN)

const sendOTP = async(req, res)=>{
   const phoneNumber = req.body
       twilio.verify.services(process.env.TWILIO_SERVICE_SID)
       .verifications.create({
        to: `+${phoneNumber}`,
        channel: 'sms'
       }).then((data)=>{
        res.status(200).send({
            message: 'Verification is sent',
            phonenumber: phoneNumber,
            data
        })
       })
}

Error:

   twilio.verify.services(process.env.TWILIO_SERVICE_SID)

在此处输入图像描述

uninstall and delete twilio from the node_modules folder and re-install it.

npm i twilio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM