简体   繁体   English

Cookie不会通过http标头api响应保存在浏览器中

[英]Cookies are not getting saved in the browser with http header api response

I am trying to use cookies to authenticate the user. 我正在尝试使用Cookie来验证用户身份。 from node.js I am sending cookies to my localhost on login with query - 从node.js,我正在使用查询登录名向我的本地主机发送cookie-

res.cookie('jwt', generateToken(user), { maxAge: 432000, domain: '.localhost.com', httpOnly: true } res.cookie('jwt',generateToken(user),{maxAge:432000,domain:'.localhost.com',httpOnly:true}

I have moddified my windos host file to point 127.0.0.1=> test.localhost.com 我已经将我的windos主机文件修改为指向127.0.0.1 => test.localhost.com

Now when I login with credentials I get this response header with set-cookie option- 现在,当我使用凭据登录时,我将获得带有set-cookie选项的响应标头-

SetCookie: jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1OGUzYTQxNWJmNjczMDBlMjQ1MjQ1YmQiLCJpYXQiOjE0OTE0ODcwMTcsImV4cCI6MTQ5MTQ; SetCookie: jwt = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1OGUzYTQxNWJmNjczMDBlMjQ1MjQ1YmQiLCJpYXQiOjE0OTE0ODcwMTQ6MT; Max-Age=432; 最大年龄= 432; Domain=.localhost.com; 域= .localhost.com; Path=/; 路径= /; Expires=Thu, 06 Apr 2017 14:04:09 GMT; Expires = Thu,2017年4月6日14:04:09 GMT; HttpOnly 仅Http

But when I see the cookies in the browser it shows I don`t have any cookies for http://test.localhost.com:3002 但是,当我在浏览器中看到Cookie时,表明我没有http://test.localhost.com:3002的 Cookie

Any help will be appreciated. 任何帮助将不胜感激。

Thanks. 谢谢。

res.cookie('jwtToken', token, { maxAge: 2 * 60 * 60 * 1000, httpOnly: true }); // maxAge: 2 hours

It's working for me. 它为我工作。 Please note that maxAge is in ms. 请注意,maxAge以毫秒为单位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM