【发布时间】:2021-10-07 16:59:55
【问题描述】:
我正在使用 Hapi-auth-jwt2 并在我的 JWT 过期后遇到问题,而不是收到 401 错误,而是收到 500 服务器错误,
这是我的代码:
const prepare = async () => {
if(prepared){
return;
}
await server.register(documentor as any);
server.auth.strategy('token','jwt',{
key:JWT_TOKEN,
validate: AuthService.verify,
verifyOptions:{
algorithms:['HS256']
}
});
server.auth.default('token');
server.validator(Joi);
server.route(routes);
prepared = true;}
如果令牌有效,它工作正常,但如果令牌无效,它假设返回 401,但我得到 500,如果我在 verifyOptions 中使用 ignoreExpiration: true,它再次工作。
这与#328 有关,因为我使用的是 v10.2.0,所以它应该已修复,但在我的情况下仍然无法正常工作。
如果令牌无效或令牌过期,validate: AuthService.verify 不会被调用。
我不知道它有什么问题。请帮忙。
如果有帮助,这里是调试错误消息
Debug: auth, unauthenticated, error, token
Error: Expired token
at Object.raiseError (/Users/tinkeshwar/Sites/proj/tool/node_modules/hapi-auth-jwt2/lib/index.js:302:45)
at Object.internals.authenticate (/Users/tinkeshwar/Sites/proj/tool/node_modules/hapi-auth-jwt2/lib/index.js:171:26)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at Object.authenticate (/Users/tinkeshwar/Sites/proj/tool/node_modules/hapi-auth-jwt2/lib/index.js:353:22)
at exports.Manager.execute (/Users/tinkeshwar/Sites/proj/tool/node_modules/@hapi/hapi/lib/toolkit.js:60:28)
at module.exports.internals.Auth._authenticate (/Users/tinkeshwar/Sites/proj/tool/node_modules/@hapi/hapi/lib/auth.js:258:30)
at Request._lifecycle (/Users/tinkeshwar/Sites/proj/tool/node_modules/@hapi/hapi/lib/request.js:372:32)
at Request._execute (/Users/tinkeshwar/Sites/proj/tool/node_modules/@hapi/hapi/lib/request.js:280:9)
调试:内部,错误 ValidationError:“属性”是不允许的
【问题讨论】: