-
Hey! When calling my graphql endpoint from the client-side, the server prints my cookies but not when I call it from the server-side (e.g. onServerPrefetch or when checking |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello! Yeah there are differences on browser's fetch vs Node's fetch. The browser adds cookies automatically but of course Node doesn't since there are no cookies in that environment. One thing you could do is access the original Or perhaps you can play with this idea: const originalFetch = globalThis.fetch
export default viteSSR(App, { routes }, ({ request }) => {
if (import.meta.SSR) {
globalThis.fetch = (url, options) => {
return originalFetch(url, { ...options, cookie: request.cookie })
}
}
}) Perhaps this is something we could do at |
Beta Was this translation helpful? Give feedback.
Hello! Yeah there are differences on browser's fetch vs Node's fetch. The browser adds cookies automatically but of course Node doesn't since there are no cookies in that environment.
One thing you could do is access the original
request
object that is passed to the main hook and read the cookies from there. Then, you can provide them to your onServerPrefetch hooks via provide/inject or any other way. I think cookies can be added to node-fetch like this: https://stackoverflow.com/questions/34815845/how-to-send-cookies-with-node-fetchOr perhaps you can play with this idea: