node.js – 为什么Passport.js给我一个中间件错误?

我正在尝试解决方法,如这里所述

https://github.com/jaredhanson/passport/issues/14

app.use(passport.initialize());
app.use(passport.session());  
app.use(app.router);
app.use(express.static(__dirname + '/public'));

工作正常

app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.use(passport.initialize());
app.use(passport.session());

DEBUG: Error: passport.initialize() middleware not in use
    at IncomingMessage.<anonymous> (/.../node_modules/passport/lib/passport/http/request.js:30:30)
    at Context.<anonymous> (/.../node_modules/passport/lib/passport/middleware/authenticate.js:92:11)
    at Context.<anonymous> (/.../core/node_modules/passport/lib/passport/context/http/actions.js:21:25)
    at Strategy.success (native)
护照后仍需要app.use(app.router).否则,您的路由将在任何Passport代码之前运行,这就是为什么您看到错误.这应该工作:

app.use(express.static(__dirname + '/public'));
app.use(passport.initialize());
app.use(passport.session()); 
app.use(app.router);
相关文章
相关标签/搜索