我的模型看起来像这样,但是当我尝试使用verifyPassword时,它显示TypeError:user.verifyPassword不是一个函数
var passport = require('passport');
var BasicStrategy = require('passport-http').BasicStrategy;
var User = require('../models/user');
passport.use(new BasicStrategy(
function(username, password, callback) {
User.findOne({ username: username }, function (err, user) {
if (err) { return callback(err); }
// No user found with that username
if (!user) { return callback(null, false); }
// Make sure the password is correct
// Error comind at this point
user.verifyPassword(password, function(err, isMatch) {
if (err) { return callback(err); }
// Password did not match
if (!isMatch) { return callback(null, false); }
// Success scenario
return callback(null, user);
});
});
}
));
最佳答案
我知道我来晚了,但是你可以做这样的事情,
passport.use(
'local',
new LocalStrategy(function(username, password, done) {
console.log('HAKSKAJS');
User.findOne({ username: username }, function(err, user) {
if (err) {
return done(err);
}
if (!user) {
return done(null, false);
}
if (user.password != password) {
return done(null, false);
}
return done(null, user);
});
})
);
参考:https://github.com/sikandar114/node-auth-pass-local/blob/master/config/passport.js