Thingamajig
Thingamajig

Reputation: 4465

Response cookie not being sent in Fetch request

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?

Upvotes: 0

Views: 1453

Answers (1)

Subham Rajput
Subham Rajput

Reputation: 22

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

Upvotes: 1

Related Questions