[英]how to notify client that reCaptcha is successful
Hello i have simple form where i have google reCaptcha v2 and when user submits form i am validating recaptcha but i also send email to user inputted email and i need to send status 200 two times here is first time where i need to send it 您好,我有一个简单的表格,我有google reCaptcha v2,当用户提交表格时,我正在验证recaptcha,但我也向用户输入的电子邮件发送电子邮件,我需要发送状态200两次,这是我第一次需要发送状态
request(verifyURL, (err, res, body)=>{
body = JSON.parse(body);
if(body.success !== undefined && !body.success){
return res.status(409).send({
success: false,
message: 'დადასტურება ვერ ვოხერხდა'
})
}
return res.status(200).send({success: true})
})
so if i send status code 200 and use return statement, won't it cause 因此,如果我发送状态码200并使用return语句,会不会导致
Can't set headers after they are sent
发送后无法设置标题
error? 错误? if it will how can i fix it?
如果它将如何解决?
Thank you! 谢谢!
You cannot send multiple response for a single request. 您不能为一个请求发送多个响应。 You can go with either: 1. Send the mail in the same controller, and when its done successfully, then only send the response back to client.
您可以选择以下两种方式之一:1.在同一控制器中发送邮件,成功完成后,仅将响应发送回客户端。 Your response will be based on both factors ie.
您的答复将基于两个因素,即。 captcha validation and email sent response or 2. if you don't wanna wait for the email process.. Just send response once your captcha is verified.. and keep the mail process execution in background.
验证码验证和电子邮件已发送响应, 或者 2.如果您不想等待电子邮件过程。.只要验证码验证后就发送响应..并在后台保持邮件过程的执行。 In this case you need to remove the return keyword or else your request will end there and mail process won't execute.
在这种情况下,您需要删除return关键字,否则您的请求将在那里结束并且邮件处理将不会执行。
However, I'll suggest you to go with the first approach. 但是,我建议您采用第一种方法。 Hope this helps :)
希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.