我看到你的req.body
包含{password: 'password', email: 'email@email.com'}
.email
不是护照正在寻找的,而是username
.您可以在HTML/JS上更改输入名称,也可以更改passportjs正在查找的默认参数req.body
.您需要在定义策略的地方应用这些更改.
passport.use(new LocalStrategy({ // or whatever you want to use usernameField: 'email', // define the parameter in req.body that passport can use as username and password passwordField: 'password' }, function(username, password, done) { // depending on your strategy, you might not need this function ... // ... } ));
在Router.post:
router.post('/', passport.authenticate('local-signup', { successRedirect: '/dashboad', failureRedirect: '/', badRequestMessage: 'Your message you want to change.', //missing credentials failureFlash: true }, function(req, res, next) { ...