Set-Cookie in response header not stored in the browser, not working

Set Cookie in response headers

Set-Cookie missing in the browser: You call an API they send you the response with set-cookie in response headers, now the expectation is the cookie should be stored in the browser with proper values. But to your surprise, the cookie passed in the set-cookie response header is mysteriously missing from your browser cookies list. You scratch your head, try again and again and are still not able to find the cookie.

There could be multiple reasons for set-cookie response headers not being able to set cookies in the browser. We have listed them down below, any of the below-mentioned scenarios can help you see the cookie in the browser.

  • You cookie has a secure flag set to true and you are trying to access it in a non secure client.
  • You are not setting the withcredentials:true in your headers while calling the API.
  • In few scenarios where you need to call your API from jQuery, you might need to add withCredentials: true in the xhrFields instead of headers.

Set withCredentials: true in headers : set-cookie in response headers

Use the below-mentioned code snippet to add withCredentials: true in headers if you are not able to set response header cookies in your browser.

headers: {
"withCredentials" : true
}

Set withCredentials: true in xhrFields : set-cookie in response headers

Use the below-mentioned code to add withCredentials: true in xhrFields if you are not able to set response header cookies in your browser.

xhrFields: {
withCredentials: true,
}

Any of the above-mentioned solutions will help you see response headers cookies in the browser.

Happy Coding 🙂

Set-Cookie in response header not stored in the browser, not working

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top