What is the `useRequestHeaders` composable used for?

Answer

useRequestHeaders() is an SSR-specific Nuxt composable that retrieves incoming HTTP request headers within the server rendering context. It's primarily used for cookie forwarding during SSR — when your Nuxt server makes internal API calls (e.g., useFetch('/api/profile')), the user's authentication cookies must be forwarded so the API can identify the user. Without this, server-side fetches would be unauthenticated. Example: const headers = useRequestHeaders(['cookie']); const { data } = await useFetch('/api/user', { headers }). It returns an empty object on the client side (where request headers don't exist), making it safe to use in universal code. This composable only works during SSR; in client-only contexts it has no effect.