简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM