Passport LocalStrategy 名称不一致 class
Passport LocalStrategy inconsistent class name
我正在创建这样的策略对象:
var strat = new LocalStrategy({
usernameField: 'email'
},
function(username, password, done) {
User.findOne({ email: username }, function (err, user) {
if (err) { return done(err); }
// Return if user not found in database
if (!user) {
return done(null, false, {
message: 'User not found'
});
}
// Return if password is wrong
if (!user.validPassword(password)) {
return done(null, false, {
message: 'Password is wrong'
});
}
// If credentials are correct, return the user object
return done(null, user);
});
}
);
在我的调试器中,我看到 strat 对象是 Class "Strategy" 的一个实例。
它不应该是 "LocalStrategy" 的实例吗,因为它是通过 LocalStrategy conscructor 创建的?
以下是使用本地策略设置 passportjs 通常执行的示例代码
var LocalStrategy = require('passport-local').Strategy;
如您所见,Strategy 是导出交易品种的名称,the name of the strategy constructor。 LocalStrategy
只是您正在使用的局部变量的名称。
我正在创建这样的策略对象:
var strat = new LocalStrategy({
usernameField: 'email'
},
function(username, password, done) {
User.findOne({ email: username }, function (err, user) {
if (err) { return done(err); }
// Return if user not found in database
if (!user) {
return done(null, false, {
message: 'User not found'
});
}
// Return if password is wrong
if (!user.validPassword(password)) {
return done(null, false, {
message: 'Password is wrong'
});
}
// If credentials are correct, return the user object
return done(null, user);
});
}
);
在我的调试器中,我看到 strat 对象是 Class "Strategy" 的一个实例。
它不应该是 "LocalStrategy" 的实例吗,因为它是通过 LocalStrategy conscructor 创建的?
以下是使用本地策略设置 passportjs 通常执行的示例代码
var LocalStrategy = require('passport-local').Strategy;
如您所见,Strategy 是导出交易品种的名称,the name of the strategy constructor。 LocalStrategy
只是您正在使用的局部变量的名称。