Twilio 手机号码验证 - Express 上未找到 VerificationCheck

Uma*_*e N 4 twilio express

找不到请求的资源 /Services/serviceSSID/VerificationCheck 是控制台中显示的错误,我的代码是

otpLogin:async (req,res)=>{
    console.log(req.body.otp);
    try {
        const isOTP = await client.verify.services(serviceSSID).verificationChecks.create({
            to:`+91${req.body.phone}`,
            code:req.body.otp
        })  
        if(isOTP)console.log(isOTP);
        return res.status(200).json({message:" mobile number verified"})       
    } catch (error) {
        console.log(error.message)
        return res.status(500).json({message:"something went wrong"})
    }
}
Run Code Online (Sandbox Code Playgroud)

phi*_*ash 8

这里是 Twilio 开发者布道者。

\n

文档中:

\n
\n

一旦验证 SID\xe2\x80\x99s,Twilio 就会删除它:

\n
    \n
  • 已过期(10 分钟)
  • \n
  • 得到正式认可的
  • \n
  • 当已达到检查代码的最大尝试次数时
  • \n
\n

如果发生其中任何一种情况,验证检查将返回 404 未找到错误,如下所示:

\n
Unable to create record: The requested resource /Services/VAXXXXXXXXXXXXX/VerificationCheck was not found\n
Run Code Online (Sandbox Code Playgroud)\n

如果您\xe2\x80\x99d 想要仔细检查给定验证所发生的情况 - 请使用验证服务下 Twilio 控制台中找到的日志:

\n

\n
\n

我发现,如果您通过快速单击提交按钮两次来提交表单两次,则验证已成功检查,然后因为它已成功删除,则第二次检查会失败,并显示类似这样的 404,这就是错误结果你看到了。为了避免这种情况,您应该通过在第一次尝试后禁用提交按钮来阻止用户两次提交表单。

\n