N
Nuxt2y ago
xergic

Forward cookie to SSR useFetch on Cloudflare Workers

Hi, I'm deploying my Nuxt app to CF Workers and need to forward auth cookie to my API on SSR using useFetch.
<script setup>
const { data } = useCustomFetch('/some-route'}
</script>
<script setup>
const { data } = useCustomFetch('/some-route'}
</script>
useCustomFetch composable looks something like this (from the docs: https://nuxt.com/docs/getting-started/data-fetching#passing-headers-and-cookies):
export const useCustomFetch = async (endpoint: string) {
const baseURL = useRuntimeConfig().public.baseUrl
const headers = useRequestHeaders(['cookie'])
const { data, error, refresh } = await useFetch(endpoint, {
baseURL,
headers,
})

return {
data,
error,
refresh,
}
}
export const useCustomFetch = async (endpoint: string) {
const baseURL = useRuntimeConfig().public.baseUrl
const headers = useRequestHeaders(['cookie'])
const { data, error, refresh } = await useFetch(endpoint, {
baseURL,
headers,
})

return {
data,
error,
refresh,
}
}
The cookie is set on client side. It works when using client side fetch but not on SSR... I tried it with setting credentials: 'include' in useFetch options, but that does not work on CF Workers as this option is not implemented and apparently not needed (more on that here: https://github.com/cloudflare/workers-sdk/issues/2514). Am I doing it wrong? Any help would be greatly appreciated.
GitHub
Issues · cloudflare/workers-sdk
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - Issues · cloudflare/workers-sdk
Nuxt
Data fetching · Get Started with Nuxt
Nuxt provides composables to handle data fetching within your application.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server