在我的node.js应用程序中使用passportjs进行身份验证,但收到上述错误。这是我的代码
app.js
passport.use(new LocalStrategy({usernameField: 'email'},function(email, password, res, done) {
res.locals.connection.query('SELECT id, password FROM users WHERE email = ?', [email], function(err, user) {
console.log(user);
if (err) {return done(err)};
if (user.length === 0) {
done(null, false);
};
const hash = user[0].password.toString();
console.log(hash);
bcrypt.compare(password, hash, function(err, res) {
if (res === true) {
return done(null, {user_id: user[0].id});
} else {
return done(null, false);
}
});
});
}
));
index.js
router.post('/', passport.authenticate('local', {
successRedirect: 'home',
failureRedirect: '/'
}));
我的代码有什么问题?