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

NeX*_*786 5 authentication jwt hapijs

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

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);
        });
Run Code Online (Sandbox Code Playgroud)

我也尝试了这个,我仍然得到错误:

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);
        });
Run Code Online (Sandbox Code Playgroud)

有谁知道这个错误是什么?是hapi-auth-jwt2不是与Hapi v17不及时?如果是这样,我已经尝试将我的依赖版本更改salzhrani/hapi-auth-jwt2#v-17https://github.com/dwyl/hapi-auth-jwt2/pull/249

我也尝试过https://github.com/dwyl/hapi-auth-jwt2/issues/248中的临时修复,但没有运气.

Gan*_*ead -1

您似乎没有为validateFunc选项提供函数。