最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - setting cookie at domain level in React with js-cookie - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 5

You 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..

发布评论

评论列表(0)

  1. 暂无评论