Node.js Passport.js LocalStrategy返回401,尽管反序列化成功

Node.js Passport.js LocalStrategy返回401,尽管反序列化成功,node.js,express,passport.js,Node.js,Express,Passport.js,我读过很多类似的主题,但没有发现任何与我类似的主题。以下是我在console中看到的内容: 85.114.2.255 - - [Thu, 10 Apr 2014 11:46:36 GMT] "GET /login HTTP/1.1" 200 >>>>>>>>>>>>>>>>>>>>>>>>>>> Local Authentication

我读过很多类似的主题,但没有发现任何与我类似的主题。以下是我在console中看到的内容:

85.114.2.255 - - [Thu, 10 Apr 2014 11:46:36 GMT] "GET /login HTTP/1.1" 200
>>>>>>>>>>>>>>>>>>>>>>>>>>> Local Authentication
Executing (default): SELECT * FROM `phpfox_user` WHERE `phpfox_user`.`email`='zelibobla@gmail.com' LIMIT 1;
<<<<<<<<<<<<<<<<<<<<<<<<<< SUCCESS
************************** SERIALIZING 13051
85.114.2.255 - - [Thu, 10 Apr 2014 11:46:37 GMT] "POST /login HTTP/1.1" 302
>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESERIALIZING 13051
Executing (default): SELECT * FROM `phpfox_user` WHERE `phpfox_user`.`user_id`=13051 LIMIT 1;
<<<<<<<<<<<<<<<<<<<<<<<<<<<< DESERIALIZED: zelibobla@gmail.com
[Function]
85.114.2.255 - - [Thu, 10 Apr 2014 11:46:37 GMT] "GET / HTTP/1.1" 401
访问控制应通过以下方式执行:

core.get( '/', [
    function (req, res, next) {
  if (req.isAuthenticated()) { return next(); }
  res.redirect('/login');
},
    function( request, response ){
console.log( "****************** GOOD! I am rendering index.html ********************" );
        return response.render( 'index.html' );
    },
] );

错误理解的关键是使用了其他策略,如BealerStrategy,对每个新请求运行身份验证过程。

为什么在
GET/
的路由处理程序中调用
passport.authenticate()
?只需尝试
core.get('/',function(request,response){response.render('index.html');})
@bnuhero也许我需要passport来执行对该页面的授权访问?
core.get( '/', [
    core.passport.authenticate( 'local' ),
    function( request, response ){
console.log( "****************** GOOD! I am rendering index.html ********************" );
        return response.render( 'index.html' );
    },
] );
core.get( '/', [
    function (req, res, next) {
  if (req.isAuthenticated()) { return next(); }
  res.redirect('/login');
},
    function( request, response ){
console.log( "****************** GOOD! I am rendering index.html ********************" );
        return response.render( 'index.html' );
    },
] );