【问题标题】:Invalid register options "value" must be an object hapi-auth-jwt2无效的寄存器选项“值”必须是一个对象 hapi-auth-jwt2
【发布时间】:2018-05-30 01:51:07
【问题描述】:

每当我尝试运行我的 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,如https://github.com/dwyl/hapi-auth-jwt2/pull/249 中所述

我还尝试了https://github.com/dwyl/hapi-auth-jwt2/issues/248 中的临时修复,但没有成功。

【问题讨论】:

  • 你能解决这个问题吗?

标签: authentication jwt hapijs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-12-21
    • 2018-07-29
    • 2018-07-10
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    相关资源
    最近更新 更多