未找到Passport身份验证中间件

时间:2018-06-06 04:48:52

标签: node.js express passport.js middleware passport-local

我有以下代码库

passport.use(new LocalStrategy({
  usernameField: 'emailAddress',
  passwordField: 'password',
  passReqToCallback: true
},
 function(req,username, password, next) {
   var res =""; // this is the real issue, I don't know where to find res, or what should I initialize to re
   console.log('psprt val');
   userController.ValidateLogin(req,res,function(userDetails){
      req.user = userDetails;
      return next(null,userDetails);
    });
 }));

userController.ValidateLogin

之类的格式返回错误
userController.ValidateLogin = function(req,res,userDetails) {
    return res.send({ Status:403, Msg: "Not allowed" });
}

但它说res.send不是一个函数,因为有res未定义,如何发送res以便我有这种消息作为回报

1 个答案:

答案 0 :(得分:1)

您不能从配置中间件发送响应(只能用于我们验证用户的护照配置)。您需要对用户进行身份验证和验证并返回,以下代码可能对您有帮助,

userController.ValidateLogin = function(req,res,callback) {
    return callback({ Status:403, Msg: "Not allowed" });
}