Here's the data fetch example: https://github.com/zeit/next.js/tree/v3-beta/examples/data-fetch
When there is a cookie, that cookie is part of the request as seen from the server _only_ when the fetch is a browser-side (non-SSR) fetch.
When fetching during SSR, the cookie is not part of the request that the server sees.
I expect the cookies to be available on the server (to Express routes) isomorphically -- during SSR and otherwise.
What the client you using for fetching?
Did you try Axios? Because I have the same problem with isomorphic-fetch
You'll have to manually pass the cookies off (reading from req) and pass them to axios / isomorphic-fetch
@kv9991 what do you mean by "client"?
@timneutkens thanks. i'll see if i can find out how to pass them to isomorphic fetch -- hopefully as a callback, because they may change, and isomorphic-fetch always needs the latest.
@tashburn you can do something like this:
const options = {
method: 'GET',
credentials: 'include', // for client side requests
};
if (req) {
options.headers = { cookie: req.headers.cookie }; // for server side request
}
const prefix = req ? `${req.protocol}://${req.get('Host')}` : window.location.origin;
return fetch(`${prefix}/admin/api/endPoint, options).then(res => ...)
@sscaff1 Thanks
Thank you all for this. Found out the solution by myself, but heh it was somewhere!
Would love to see this as part of the docs explaining how isomorphic fetch works.
Most helpful comment
@tashburn you can do something like this: