每当我尝试运行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不一致吗?如果是这样,我已尝试将我的依赖关系版本更改为salzhrani/hapi-auth-jwt2#v-17
LowercaseNamingStrategy
我还尝试了https://github.com/dwyl/hapi-auth-jwt2/pull/249中的临时修复但没有运气。