Skip to content

Does the dev server include cookies? #49

Answered by frandiox
m4rvr asked this question in Q&A
Discussion options

You must be logged in to vote

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-fetch

Or perhaps you can play with this idea:

const originalFetch = globalThis.fetch

export default viteSSR(App, { routes }, ({ request }) => {
  if (import.meta.SSR

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@m4rvr
Comment options

Answer selected by m4rvr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants