request.auth.session.set(user_info) 不工作 HapiJS

request.auth.session.set(user_info) not working HapiJS

这是我的策略,它是在 server.register() 上定义的。我的工作基于一个教程,它是从字面上复制的,但它不起作用。

    server.auth.strategy('standard', 'cookie', {
        password: 'somecrazycookiesecretthatcantbeguesseswouldgohere', // cookie secret
        cookie: 'app-cookie', // Cookie name
        isSecure: false, // required for non-https applications
        redirectTo: '/login',
        ttl: 24 * 60 * 60 * 1000 // Set session to 1 day
    });

    server.auth.default({
        strategy: 'standard',
        mode: 'required',
        scope: ['admin']
    });

这是我出现错误的登录路径:

server.route({
    method: 'POST',
    path: '/login',
    config: {
        auth: false,
        validate: {
            payload: {
                email: Joi.string().email().required(),
                password: Joi.string().min(2).max(200).required()
            }
        },
        handler: function (request, reply) {

            getValidatedUser(request.payload.email, request.payload.password)
                    .then(function (user) {

                        if (user) {
                            //ERROR OCCURS HERE: IT SAYS SESSION IS UNDEFINED
                            request.auth.session.set(user);
                            return reply('Login Successful!');
                        } else {
                            return reply(Boom.unauthorized('Bad email or password'));
                        }

                    });
//                        .catch(function (err) {
//                            return reply(Boom.badImplementation());
//                        });

        }
    }
});

我已经尝试了很多东西,但这部分对这项工作至关重要,我找不到有同样问题的人。请帮忙!

hapi-auth-cookie 改变了设置和清除 cookie 的方式。从版本 5.0.0 开始,使用 request.cookieAuth.set() 和 request.cookieAuth.clear()。您使用的插件版本可能比本教程 package.json 中使用的插件版本更新。

来源: https://github.com/hapijs/hapi-auth-cookie/commit/d233b2a3e4d0f03ef53b91b7929b8dbadbff624c