5

I have a problem with my fetch request. For some reasons, it isn't sending my cookies when I'm making request to my server. For example, I'm using such fetch request

fetch('/api/islogged', {
      method: 'GET',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Cache': 'no-cache'
      },
      credentials: 'include',
    })

and even if I'm already logged in, it still says that I'm not. But, if I go directly to www.localhost.com/api/islogged in my browser, it returns correct answer

omkaartg
  • 2,676
  • 1
  • 10
  • 21
Leonid Gordun
  • 361
  • 1
  • 4
  • 14
  • From what you're saying it seems like you are running a local server so it shouldn't be the cause, but just in case, know that cookies won't work from a local HTML file opened directly in the browser. – Domino Dec 04 '17 at 17:57
  • Possible duplicate of [Fetch API with Cookie](https://stackoverflow.com/questions/34558264/fetch-api-with-cookie) – Vipin Kumar Dec 04 '17 at 18:44
  • @VipinKumar Possibly not since he is using credentials: 'include', which is an answer in the duplicate – mplungjan Dec 04 '17 at 21:23

1 Answers1

-2

Try using credentials: 'same-origin' instead of include. That should work.

pritam
  • 102
  • 1
  • 1
  • 4