通过发送验证链接验证用户并使用 Passport Local 策略 Nodejs 将用户保存在 Req 中

问题描述

用户尝试注册(以验证用户电子邮件)时,我正在发送一个指向用户电子邮件链接,因此当用户单击该链接时,它将在后端调用验证功能,如果成功,则将用户保存在会话中。

>
  const verifyUser = (models) => (req,res,next) => {
  const { id,email } = req.query;
  models.user.findOne({ where: { usr_email: email } }).then((isUserFound) => {
    if (isUserFound) {
      if (isUserFound.usr_hash == id) {
        passport.authenticate("login",{
          failureRedirect: "/Failed",successRedirect: "http://domain-name.com",})(req,next);
      }
    }
  });
};

调用这个 localStrategy 只是为了在 Req 中保存用户。但是如何在护照认证中直接传递电子邮件密码?因为在req中没有正文中的邮箱密码

passport.authenticate("login",{
              failureRedirect: "/Failed",next);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)