Defining $fetch
within useFetch()
doesnt pass cookies on SSR #27996
Open
Description
Environment
- Operating System: Darwin
- Node Version: v21.6.1
- Nuxt Version: 3.12.3
- CLI Version: 3.12.0
- Nitro Version: 2.9.6
- Package Manager: bun@1.1.13
- Builder: -
- User Config: future, extends, modules, runtimeConfig, routeRules, i18n
- Runtime Modules: @nuxt/ui@^2.17.0
- Build Modules: -
Reproduction
https://github.com/MickL/nuxt-bug-use-fetch-custom-fetch
- Run
bun dev
to start Nuxt app on port 3000 and Nitro app on port 3001 - Press button "set cookie"
- Reload page 1: Cookie is not set
- Navigate to page 2, back to page 1: Cookie is set
Describe the bug
When setting $fetch
param within useFetch()
options Nuxt does not forward cookies on SSR:
await useFetch(url, {
...options,
$fetch, // Or `$fetch: useNuxtApp().$customFetch`
});
On the server (separate Nitro / H3 app) the cookie is undefined:
export default defineEventHandler(async (event) => {
console.log(getCookie(event, 'auth_session'));
});
This happens only on SSR. When the Nuxt app is already loaded in the browser and navigating between pages everything works as expected.
Additional context
Potentially this is also an issue of using routeRules proxy?
Activity