我想用Knex、Express和NodeJS构建一个应用程序。我上传了一个柱塞作为代码。我还没有前台,我在用邮递员。
注册工作正常,但登录时我得到
{
"status": "User not found"
}或
{
"message": "Missing credentials"
}哪个似乎是问题所在?为什么登录时看不到我插入到db中的用户?
发布于 2018-09-13 08:52:57
我找出了问题所在,并对local.js中的函数进行了如下修改:
passport.use('local', new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
},
function (username, password, done) {
knex('user')
.where('email', '=', username)
.then((err, user) => {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: 'Incorrect email.' });
}
if (!user.isValid(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
})
}
));email不是passportjs正在寻找的东西,而是username。
https://stackoverflow.com/questions/52309382
复制相似问题