简体   繁体   English

使用 Twilio Nodejs 进行电话身份验证

[英]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.我正在尝试使用 twilio 发送短信以使用 nodejs 进行 OTP 身份验证,但出现错误。 Kindly, can somebody help me debug it.请有人可以帮我调试它。 Below is my code to send the OTP SMS.下面是我发送 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.从 node_modules 文件夹中卸载并删除 twilio 并重新安装。

npm i twilio npm 我 twilio

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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