admin 管理员组文章数量: 1086019
I have a React application. Currently I am using js-cookie to manage my cookies. Right now I am facing this problem: I need the cookies to be available at domain level and not subdomain level.
Eg: my site is running under mysite.mydomain, then I need the cookies to be available to any site that is running under .mydomain
I read in other post that I can be achievable just setting the path to "/". SO I mad this:
Cookies.set('session', myvalue ,{path:'/'});
However it's still creating the cookie at mysite.mydomain
So, what else can I do? I dont want to writte the domain directly when I create the cookie due that it's not clean and also the development is under localhost and it would get a mess. So, I am looking for a clean solution
Thank you very much
I have a React application. Currently I am using js-cookie to manage my cookies. Right now I am facing this problem: I need the cookies to be available at domain level and not subdomain level.
Eg: my site is running under mysite.mydomain., then I need the cookies to be available to any site that is running under .mydomain
I read in other post that I can be achievable just setting the path to "/". SO I mad this:
Cookies.set('session', myvalue ,{path:'/'});
However it's still creating the cookie at mysite.mydomain.
So, what else can I do? I dont want to writte the domain directly when I create the cookie due that it's not clean and also the development is under localhost and it would get a mess. So, I am looking for a clean solution
Thank you very much
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Oct 2, 2017 at 20:23 Sredny M CasanovaSredny M Casanova 5,06127 gold badges78 silver badges119 bronze badges 2- @mplungjan yes, am sure, I check it many times loooking for a reason but nothing. Doesnt have to be something with the 'domain' attribute? or with 'path' is enough? – Sredny M Casanova Commented Oct 2, 2017 at 20:41
- RTM: github./js-cookie/js-cookie#domain – mplungjan Commented Oct 2, 2017 at 21:18
1 Answer
Reset to default 5You need to use domain
Cookies.set('session', myvalue ,{ domain: 'mydomain.' });
More info.
This should work according to the MDN documentation. In case it doesn't try setting a dot in the beginning .mydomain.
.
本文标签: javascriptsetting cookie at domain level in React with jscookieStack Overflow
版权声明:本文标题:javascript - setting cookie at domain level in React with js-cookie - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744062173a2526921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论