gpt4 book ai didi

authentication - 无效的寄存器选项 "value"必须是一个对象hapi-auth-jwt2

转载 作者:行者123 更新时间:2023-12-03 15:03:23 26 4
gpt4 key购买 nike

每当我尝试运行hapi服务器时,我都会收到一个奇怪的错误Invalid register options "value" must be an object。我似乎无法弄清楚这个问题。这是我的代码:

await server.register(require('hapi-auth-jwt2'), (err) => {
if (err) console.log(err);

server.auth.strategy('jwt', 'jwt', {
key: secretKey,
verifyOptions: { algorithms: ['HS256'] }
});

glob.sync('api/**/routes/*.js', {
root: __dirname
}).forEach(file => {
const route = require(path.join(__dirname, file));
server.route(route);
});
}).catch(err => {
console.log(err);
});

我也尝试过此方法,但仍然出现错误:
const options = {
key: secretKey,
verifyOptions: { algorithms: ['HS256'] }
};

await server.register({
register: require('hapi-auth-jwt2'),
options
}, (err) => {
if (err) console.log(err);
// We're giving the strategy both a name
// and scheme of 'jwt'
server.auth.strategy('jwt', 'jwt', {
key: secretKey,
verifyOptions: { algorithms: ['HS256'] }
});

glob.sync('api/**/routes/*.js', {
root: __dirname
}).forEach(file => {
const route = require(path.join(__dirname, file));
server.route(route);
});
}).catch(err => {
console.log(err);
});

有谁知道这个错误是关于什么的?仅仅是 hapi-auth-jwt2与Hapi v17无关紧要吗?如果是这样,我已经尝试将自己的依赖项版本更改为 https://github.com/dwyl/hapi-auth-jwt2/pull/249中提到的 salzhrani/hapi-auth-jwt2#v-17
我也尝试过 https://github.com/dwyl/hapi-auth-jwt2/issues/248中的临时修复,但没有运气。

最佳答案

似乎您没有为validateFunc选项提供功能。

关于authentication - 无效的寄存器选项 "value"必须是一个对象hapi-auth-jwt2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47839345/

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