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