isomorphic-fetch icon indicating copy to clipboard operation
isomorphic-fetch copied to clipboard

Fetching during SSR (using Next) should include cookies

Open tashburn opened this issue 8 years ago • 4 comments
trafficstars

Cookies are included in the Express routing when the fetch code runs on the browser, but when run during SSR with Next, the cookies are not available. I'd expect them to be.

Adding credentials: 'same-origin' or credentials: 'include' to the fetch options did not make a difference.

tashburn avatar Jul 03 '17 21:07 tashburn

Are you sure? This is a very common use case. I believe credentials really should work…

matthew-andrews avatar Jul 03 '17 22:07 matthew-andrews

@matthew-andrews in discussions with the Next people, one said "I have the same problem with isomorphic-fetch", and another said "You'll have to manually pass the cookies off (reading from req) and pass them to axios / isomorphic-fetch"

Any idea how I "pass the cookies" to isomorphic-fetch?

credentials only works when the fetch happens on the browser client. when the fetch happens during SSR, credentials does not work.

tashburn avatar Jul 06 '17 03:07 tashburn

Oh right, on the server, I see…… I think you'd need to add the cookie header manually in that environment. Something like this…

fetch(url, {
  headers: { Cookie: 'name=value' }
});

matthew-andrews avatar Jul 06 '17 03:07 matthew-andrews

on the server, isomorphic-fetch just proxies node-fetch underneath, which as you say does not implement credentials:- https://github.com/bitinn/node-fetch#class-request

matthew-andrews avatar Jul 06 '17 03:07 matthew-andrews