can';t设置';确认';使用jwt和mongoose确认电子邮件时,值为true

can';t设置';确认';使用jwt和mongoose确认电子邮件时,值为true,mongoose,jwt,mongoose-schema,email-verification,Mongoose,Jwt,Mongoose Schema,Email Verification,我通过电子邮件确认: 如果“确认”值设置为false,则用户无法登录 当他们点击包含jwt的链接时,该值应该从false变为true,但事实并非如此,因为我在尝试登录“Email is not confirmation”(电子邮件未确认)时仍然会出现错误。我有什么做错了吗 router.get('/confirmation/:token', async (req, res, next) => { try { const { user: { id } } = jwt.

我通过电子邮件确认:

如果“确认”值设置为false,则用户无法登录

当他们点击包含jwt的链接时,该值应该从false变为true,但事实并非如此,因为我在尝试登录“Email is not confirmation”(电子邮件未确认)时仍然会出现错误。我有什么做错了吗

router.get('/confirmation/:token', async (req, res, next) => {
    try {
        const { user: { id } } = jwt.verify(req.params.token, REG_SECRET);
        await models.User.update({confirmed: true }, { where: { id } });

      } catch (e) {
        res.status('404');
      }

     const login = " Your email is verified!"
     return res.render('index', {login: login});
});

您需要将相关代码作为格式化文本发布为问题的一部分。嘿,玛丽,您单击的每个链接都是带有代码的图片:)否,因此要求相关代码成为问题文本的一部分。不是外部链接。我们如何复制代码来测试它?您将提供一个最小、完整且可验证的示例。是吗?是的,你说得对)别客气,托尼,欢迎来到Stack Overflow。
const UserSchema = mongoose.Schema({
  username: {
    type: String
  },
  password: {
    type: String
  },
  email: {
    type: String
    },
  confirmed: {
     type: Boolean,
     defaultValue: false
   },
  name: {
    type: String
  },
    timestamps: {
      type: Boolean
    }
});
  if (user.confirmed === true) {
            User.comparePassword(password, user.password, (err, isMatch) => {
          if (err) throw err;
            if (isMatch) {
                return done(null, user);
              } else  {
                  return done(null, false, { message: 'Invalid password' });
                }
             });
      } else {
        return done(null, false, { message: 'Please confirm your email to login'});
      }
router.get('/confirmation/:token', async (req, res, next) => {
    try {
        const { user: { id } } = jwt.verify(req.params.token, REG_SECRET);
        await models.User.update({confirmed: true }, { where: { id } });

      } catch (e) {
        res.status('404');
      }

     const login = " Your email is verified!"
     return res.render('index', {login: login});
});