1

I'm trying to set a cookie when a user logs into the application but i can't seem to get the cookie to get stored on chrome or firefox but it does work on postman.

Here is the part of the code when i try to set my cookie.

  res.cookie("jwt", token, {
    domain: ".localhost",
    path: "/",
    expires: new Date(
      Date.now() + process.env.JWT_COOKIE_EXPIRES_IN * 24 * 60 * 60 * 1000
    ),
    httpOnly: true
  });

POSTMAN output :

enter image description here

And my CORS setup :

enter image description here

Note : my server is on port 3900 and my client is on 3000

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
CHADTO
  • 331
  • 1
  • 4
  • 12

1 Answers1

1

use localhost:3000 as domain because it is your actual domain for client side. localhost by default take port 80 as http request.

res.cookie("jwt", token, {
    domain: ".localhost:3000",
    path: "/",
    expires: new Date(
      Date.now() + process.env.JWT_COOKIE_EXPIRES_IN * 24 * 60 * 60 * 1000
    ),
    httpOnly: true
  });
Pawan Sah
  • 153
  • 1
  • 1
  • 9