NuxtN
Nuxt3y 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>


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,
  }
}


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
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - Issues · cloudflare/workers-sdk
Nuxt
Nuxt provides composables to handle data fetching within your application.
Was this page helpful?