NuxtN
Nuxt9mo ago
12 replies
Coton

Having the fetch context (SSR) in a composable

Hello,

Currently if i'm using the following code in a page, it works.

await $fetch("/api/services?inservice=1");

This SSR endpoint need session auth, on a page it works.

Because I would like to have this logic on several pages/components, I exported it on a composable file.


export async function fetchInService(): Promise<UserServiceDetails[]> {
  const runtimeConfig = useRuntimeConfig();
  return await $fetch("/api/services?inservice=1");
}

But now, i'm getting a 403 because $fetch seems to not be aware of nuxt context anymore.

What is the easiest way to fix that?
Was this page helpful?