I get a strange error Invalid register options "value" must be an objectwhenever I try to start my hapi server. It seems I can not understand this problem. This is my code:
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);
});
I tried this too and I still get the error:
const options = {
key: secretKey,
verifyOptions: { algorithms: ['HS256'] }
};
await server.register({
register: require('hapi-auth-jwt2'),
options
}, (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);
});
Does anyone know what this error is? Is it just that it is hapi-auth-jwt2not updated with Hapi v17? If so, I tried changing the version of the dependencies to salzhrani/hapi-auth-jwt2#v-17as indicated in https://github.com/dwyl/hapi-auth-jwt2/pull/249
I also tried the interim fix at https://github.com/dwyl/hapi-auth-jwt2/issues/248 with no luck.
source
share