简体   繁体   English

如何通过使用 NodeJS 发送验证码来验证用户 email?

[英]How to authenticate user email by sending a verification code using NodeJS?

I want to send a verification code to the registered Email ID of the user during signup.我想在注册时向用户注册的Email ID发送验证码。 All the tutorials I found send a verification link using sendgrid API.我找到的所有教程都使用 sendgrid API 发送验证链接。

Is there any way I this could be done using a verification code instead?有什么办法可以用验证码代替吗?

you can do it by yourself.你可以自己做。

  • in the user schema in the DB you need a boolean place for isAuthenticated and a string place for the auth code.在数据库的用户模式中,您需要一个 boolean 位置用于 isAuthenticated 和一个字符串位置用于身份验证代码。
  • generate some code, if you're working with nodejs UUID package for NPM is a great package.生成一些代码,如果您正在使用 nodejs UUID package for NPM 是一个很棒的 package。
  • when a user is registered - save false by default, generate the code and:当用户注册时 - 默认保存 false,生成代码并:
    1. save it into the user in the DB将其保存到数据库中的用户中
    2. send a mail to the user with a link to the endpoint on your server something like /:userid/:authcode向用户发送一封邮件,其中包含指向您服务器上端点的链接,例如/:userid/:authcode
  • on the server - build this endpoint, select the user from the DB by the ID you got on the parameter, check if the code you got on the param is the same as the one saved in the user you just selected, and if so - update the user to true在服务器上 - 构建此端点,select 来自数据库的用户通过您在参数上获得的 ID,检查您在参数上获得的代码是否与您刚刚选择的用户中保存的代码相同,如果是 -将用户更新为 true
  • last thing - on login - check if the auth is true, and if not - send a specific error so you cant catch it on the client and display a nice detailed error message最后一件事 - 登录时 - 检查身份验证是否为真,如果不是 - 发送特定错误,以便您无法在客户端上捕获它并显示一个很好的详细错误消息

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

相关问题 如何使用 nodejs 对电子邮件进行身份验证? 我收到一封关于用户提交的电子邮件的电子邮件,然后我点击我端的一个链接来验证这封电子邮件 - How can I authenticate an email using nodejs? I get an email for user submitted email, then I click a link on my end to verify this email 在Node.js中使用SecretToken进行电子邮件验证 - Email verification using secrettoken in nodejs 如何使用NodeJS在Podio中验证用户身份 - How to authenticate as an User in Podio using NodeJS 用户 email 使用 nodemailer 验证 - user email verification using nodemailer 尝试使用NodeJS实施电子邮件验证 - Trying to Implement Email Verification using NodeJS Email用nodejs验证 - Email verification with nodejs 如何发送验证电子邮件并每 2 小时应用一次 cron 作业,直到用户在 nodejs 中得到验证? - How to send a verification email and apply a cron job for every 2 hours until the user get verifed in nodejs? AWS Cognito - 创建用户而不向他们发送验证 email - AWS Cognito - Create user without sending them a verification email 使用Node.js Web服务器但不使用框架对用户进行身份验证 - Authenticate a user using a nodejs web server but no framework 我们如何在将它发送给nodejs中的用户之前执行javascript代码? - How can we execute a javascript code before sending it to the user in nodejs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM