Koa2 + passport + passport-jwt 做 auth 验证报错。
const passport = require('passport');
const { Strategy, ExtractJwt } = require('passport-jwt');
const jwt = new Strategy({
jwtFromRequest: ExtractJwt.fromAuthHeader(),
secretOrKey: `secret`,
}, async (payload, done) => {
console.log(payload, done);
});
passport.use(jwt);
exports.authJWT = passport.authenticate('jwt', {
session: false,
});
/Users/lbc/Documents/gitstore/echo/node_modules/passport-jwt/lib/extract_jwt.js:55
if (request.headers[AUTH_HEADER]) {
^
TypeError: Cannot read property 'headers' of undefined
at JwtStrategy._jwtFromRequest (/Users/lbc/Documents/gitstore/echo/node_modules/passport-jwt/lib/extract_jwt.js:55:20)
at JwtStrategy.authenticate (/Users/lbc/Documents/gitstore/echo/node_modules/passport-jwt/lib/strategy.js:83:22)
at attempt (/Users/lbc/Documents/gitstore/echo/node_modules/passport/lib/middleware/authenticate.js:349:16)
at authenticate (/Users/lbc/Documents/gitstore/echo/node_modules/passport/lib/middleware/authenticate.js:350:7)
at Object.<anonymous> (/Users/lbc/Documents/gitstore/echo/route/user.js:7:16)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/lbc/Documents/gitstore/echo/route/index.js:3:14)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用
koa-passport