无法在 hapijs 路由和 haps-auth-cookie 中设置模式尝试

Can't set mode try in hapijs route and haps-auth-cookie

我是 Hapijs 的新手,我的路由身份验证配置有一些问题。

错误:

[1] "auth" must be a string
[2] "strageties" is not allowed

路线

exports.register = (server, options, next) => {

    server.route({
        method: 'GET',
        path: '/',
        config: {
            auth: {
                mode: 'try',
                strageties: ['session'] // or strategy: 'session'
            },
            handler: (request, reply) => {
                return reply.view('partials/index');
            }
        }
    });

    return next();
};

exports.register.attributes = {
    name: 'routes-home'
};

策略

    server.auth.strategy(Providers.Session, 'cookie', {
        password: config.server.SECRET,
        redirectTo: '/login',
        isSecure: false
    });

我正在使用 happy-auth-cookie 和 bell。我还有更多策略,例如 github、twitter...如果我将身份验证设置为仅会话,它就可以工作。 授权:'session'

成功了。我必须像这样为我的策略提供模式:

server.auth.strategy(Providers.Session, 'cookie', 'try', { //<= 'try'
    password: config.server.SECRET,
    isSecure: false
});

我还必须删除 redirectTo 属性。 在策略级别设置模式提供了我正在寻找的功能。基本上,我需要检查用户是否在每条路线上登录,因为我的导航菜单会根据结果而改变。将路由授权配置设置为 'session',以便只有登录用户才能访问的路由。

请参考:server.auth.stragety.