ppseafield
From a pinia store: $fetch() doesn't send headers serverside, and useFetch causes hydration errors.
I have a pinia store that fetches from a server api endpoint. That endpoint reads an HTTP only cookie (a jwt) for authentication.
On page load if I use $fetch in the store, the cookie isn't passed to the endpoint, making the request unauthenticated, which AFAICT is intended behavior. If I use useFetch, there are hydration errors on the page.
The page works fine if I fetch from the store via onMounted() or navigate to the page, but hitting refresh on the pages causes one of those two errors. Using onMounted I don't get server side rendering, which is probably fine for this paged.
Is there a way to either send that header with $fetch or a way to use useFetch in side a pinia store? Is there a different way that would avoid those problems?
5 replies