gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 23:07:05 26 4
gpt4 key购买 nike

我正在尝试这里描述的解决方法

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)

最佳答案

你仍然需要在 Passport 之后 app.use(app.router)。否则,您的路线将在任何 Passport 代码之前运行,这就是您看到错误的原因。这应该有效:

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

关于node.js - 为什么 Passport.js 给我一个中间件错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10497349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com