1

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

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

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? Commented Oct 2, 2017 at 20:41
  • RTM: github.com/js-cookie/js-cookie#domain Commented Oct 2, 2017 at 21:18

1 Answer 1

5

You need to use domain

Cookies.set('session', myvalue ,{ domain: 'mydomain.com' });

More info.

This should work according to the MDN documentation. In case it doesn't try setting a dot in the beginning .mydomain.com.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.