cookie没有在hapi-auth-cookie插件的浏览器中设置

时间:2018-04-10 19:23:33

标签: reactjs cookies axios hapijs hapi-auth-cookie

我已经为我的后端使用hapi js并对我的前端作出反应。前端服务器在localhost端口3000上运行,后端在8000上运行。所以我有2条这样的路由 - let userDetails = { method: "GET", path: "/api/user/userdata", config: { description: 'Get userdata', notes: 'Returns a todo item by the id passed in the path', tags: ['api', 'User Data'], cors: corsHeaders, auth: { strategy: 'restricted', } }, handler: (request, h) => { return h.response(userData) } }

let createUser = {
method: "POST",
path: "/api/user/userdata",
config: {
    tags: ['api', 'User Data'],
    description: 'Upload User data to the db',
    cors: corsHeaders,
},
handler: async (request, h) => {

    const { username, emailId, password } = request.payload
    request.cookieAuth.set({ username })
    return h.response('cookie created!')

}

}

现在'post'路由通过request.cookieAuth.set({username})设置cookie, 因此,当我通过邮递员申请发布时,它在邮递员中设置cookie,并且get路由发送数据没有任何问题。但是在浏览器中,cookie没有被设置。

我正在使用hapi-auth-cookie插件,注册就像这样 -

await server.register(HapiAuthCookie)

server.auth.strategy('restricted', 'cookie',{
    password: 'AudhASp342SID3acdh83CDASHciAS93rashdiva34a',
    cookie: 'session',
    isSecure: false,
    ttl: 7 * 24 * 60 * 60 * 1000,
})
有人请帮忙

0 个答案:

没有答案