1

I am deploying the backend on a server using a subdomain and the frontend on another subdomain. However, the cookies are not being set for the frontend. I have tried using the domain: '.domain.com' option to set the cookies, but it is not working. Can anyone help me figure out what the issue might be?

I tried the solutions and still the cookie was not set:

res.cookie('myCookie', 'myValue', { domain: '.example.com' });

res.cookie('myCookie', 'myValue', { domain: '.example.com', path: '/', secure: true });

1 Answers1

0

This may answer your question https://stackoverflow.com/a/23086139/22070854, but I think you forgot to specify the expiry date of the cookie.

Assuming you use express, you can do this:

res.cookie('cookieName', 'cookieValue', {

  // the domain name
  domain: '.domain.com',

  // the expiry time relative to the current time (in milliseconds), 1 hour here
  maxAge: 1000 * 60 * 60,

  // the path
  path: '/'
});
Community
  • 1
  • 1
nathanTi
  • 21
  • 6