【问题标题】:hapi-auth-cookie: throws error when reading cookies to access locked contenthapi-auth-cookie:读取 cookie 以访问锁定内容时抛出错误
【发布时间】:2018-05-30 02:11:26
【问题描述】:

我使用 hapi-auth-cookie 来保存 cookie 并创建会话。 某些部分被锁定,未经身份验证的用户不允许访问它。 当用户未登录时,他被成功重定向到登录路由。验证后,当用户再次单击同一链接时,它很可能在处理 cookie 时引发错误。这是会话注册:

plugin.auth.strategy('session', 'cookie', {
    password: 'hapissajafdhafdjahyfjkdgsyjasfydukfeyafdheavjdfaejmyfdja',
    cookie: 'sid-cuboid',
    redirectTo: '/',
    isSecure: false,
    validateFunc: function(request, session) {
        var cached = cache.get(session.sid);
        var out = {
            valid: !!cached
        };

        if (out.valid) {
            out.credentials = cached.account;
        }

        return out;
    }
});

这是我的路线:

plugin.route({
        method: 'GET',
        path: '/edit/{courseName}/{testNo}/{plunkId}',
        config: {
            auth: {
                strategy: 'session'

            },
            plugins: {
                'hapi-auth-cookie': {
                    redirectTo: '/'
                }
            }
        },
        handler: function(request, reply) {
            var server = this.config.server;
            var param = request.params;
            var courseName = request.params.courseName;
            var context = {
                "url": {
                    "run": ""
                }
            };

            reply.view("editor", context);

        }

    });

这是我得到的错误:

Debug: internal, implementation, error 
    TypeError: Uncaught error: Cannot read property 'apply' of undefined
    at bound (domain.js:280:13)
    at runBound (domain.js:293:12)
    at /home/satnam-sandhu/Workstation/cuboid.io/node_modules/glue/node_modules/hoek/lib/index.js:858:22
    at doNTCallback0 (node.js:419:9)
    at process._tickDomainCallback (node.js:389:13)

注意:我正在使用 nodejs@4.2.2 和 hapi-auth-cookie@6.1.1

【问题讨论】:

    标签: javascript node.js cookies session-cookies hapijs


    【解决方案1】:

    通过删除 validateFunc 解决了上述问题。错误原因仍然未知。

    【讨论】:

      猜你喜欢
      • 2014-10-10
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多