req.body不存在(我猜??)

时间:2019-04-02 14:51:35

标签: node.js express passport.js

我有此代码:

  passport.use('signup', new LocalStrategy({
    usernameField: 'email',
    passwordField: 'password',
    passReqToCallback: true
  }, (req, email, password, done) => {
        User.findOne({ 'email': email }, (err, user) => {
        if (err) return done(err);
        if (user) return done(null, false, req.flash('registerMessage', 'This e-mail is already taken by someone else!'));
        if (req.body.password !== req.body.password2) return done(null, false, req.flash('registerMessage', 'Passwords do not match!'))
  }));

带有if (req.body.password !== req.body.password2) return done(null, false, req.flash('registerMessage', 'Passwords do not match!'))的部分可以很好地显示Flash消息,但是如果我将此代码添加到开头:if (!req.body.email || !req.body.username || !req.body.password) return done(null, false, req.flash('registerMessage', 'Please fill all the lines')则它什么也不做(没有消息),就像req.body中没有数据一样。我该如何解决?

谢谢您的帮助

0 个答案:

没有答案