Search code examples
javascriptreactjscookieslocal-storage

Share localstorage/Cookies across the different domain


I have a domain ab.example.com and want to share the same localstorage/Cookies across different subdomain example xyz.example.com

I have tried to share by post message function but its not working.

kindly help me solve this problem thanks in advance mate.


Solution

  • Domain attribute

    The Domain attribute specifies which hosts can receive a cookie. If the server does not specify a Domain, the browser defaults the domain to the same host that set the cookie, excluding subdomains. If Domain is specified, then subdomains are always included. Therefore, specifying Domain is less restrictive than omitting it. However, it can be helpful when subdomains need to share information about a user.

    For example, if you set Domain=mozilla.org, cookies are available on subdomains like developer.mozilla.org.