0

I'm currently sending a cookie back from my Node server like this:

res.setHeader('Set-Cookie', [`session=${sessionCookie}; HttpOnly; Secure`]);
res.status(200).send(JSON.stringify({status: 'success'}));

When I go to Chrome, I can see in the Network call that the session cookie is received. It's not making its way over to the Application tab.

I'm then going to make my call using Fetch (have tried both 'include' and 'same-origin' but cannot find the cookie in the Fetch request.

fetch(`http://localhost:3000/api/test`,
    {
      method: 'POST',
      credentials: 'same-origin'
    })

Is there anything wrong with this setup that may be causing the cookie to not make its way into the request?

Thingamajig
  • 4,107
  • 7
  • 33
  • 61

1 Answers1

1

In options object you need to pass same-origin in mode and include in credentials.

Hope this link will help you to solve the issue https://stackoverflow.com/a/42735086/6712441

Thanks

  • Awesome! That worked for sending the current cookies, but still didn't send the "session" cookie. Any idea why that specific cookie has not been sent and handled correctly? – Thingamajig Aug 19 '19 at 16:43
  • Send cookie like this `res.cookie("session", sessionCookie, {httpOnly: true, secure: true});` – Subham Rajput Aug 19 '19 at 17:07
  • I think that's a function of Express, res.cookie is not a function for me. – Thingamajig Aug 19 '19 at 17:13
  • If you are not using express, you can try with **res.writeHead()** function. This [https://stackoverflow.com/a/3409200/6712441] should help you. – Subham Rajput Aug 19 '19 at 17:29