0

I'm trying to set a cookie using javascript in the subdomain and make it available for all subdomains but it doesn't get set unless I explicitly specify the subdomain or skip out the domain parameter entirely which only sets the cookie for that subdomain and can't be read by others.

I have taken a look at setting cross-subdomain cookie with javascript as well as Share cookie between subdomain and domain and also https://www.thoughtco.com/javascript-by-example-2037272 which describe the exact method I've tried but it doesn't seem to be working.

This is the code I have currently running but doesn't work, the current subdomain I am trying it on is admin.example.com and would like to get the same cookie on web.example.com

document.cookie = auth-cookie=abc; expires=Wed, 08 Jul 2020 12:30:55 GMT; path=/; domain=example.com;

If I try either of the following code from admin, the cookie does get set but I am not able to access it in other sub domains

document.cookie = auth-cookie=abc; expires=Wed, 08 Jul 2020 12:30:55 GMT; path=/; document.cookie = auth-cookie=abc; expires=Wed, 08 Jul 2020 12:30:55 GMT; path=/; domain=admin.example.com;

Jude Fernandes
  • 6,969
  • 9
  • 43
  • 82

0 Answers0