【发布时间】:2014-11-06 06:19:12
【问题描述】:
我想使用 req.flash("message" : error ) 来支持 SailsJS 中的 passportJS 错误消息回调。但是,PassportJS 在回调期间不处理以下内容:(类似帖子:PassportJS Custom Authenticate Callback Not Called)
//there is no req found
req.flash("message" , "invalid password");
如果有类似的东西,这通常会没事的:
function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
//....
req.flash("message" , "invalid password");
}
但我不能在 passport.use 中使用它。
/services/passport.js
passport.use(new HttpBasicStrategy(
function(username, password, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// Find the user by username. If there is no user with the given
// username, or the password is not correct, set the user to `false` to
// indicate failure. Otherwise, return the authenticated `user`.
findByUsername(username, function(err, user) {
if (err)
return done(null, err);
if (!user) {
return done(null, false, {
message: 'Unknown user ' + username
});
}
bcrypt.compare(password, user.password, function (err, res) {
if (!res){
--> //there is no req found
--> req.flash("message" , "invalid password");
return done(null, false, {
message: 'Invalid Password'
});
}
var returnUser = {
username: user.username,
createdAt: user.createdAt,
id: user.id
};
return done(null, returnUser, {
message: 'Logged In Successfully'
});
});
})
});
}
));
还有其他方法可以调用 req.flash 吗?我对express和sailsjs还很陌生,请原谅我的无知。
【问题讨论】:
标签: express request response sails.js passport.js