From 8ab0989ae4f4ab8bc925c76f6f2e57cf87caddc1 Mon Sep 17 00:00:00 2001 From: Paulo Queiroz <16908491+raggesilver@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:05:12 -0300 Subject: [PATCH 1/2] Include SSR instructions in the README, fixes #97 --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 03952514..e2d38420 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,17 @@ export default defineNitroPlugin(() => { }) ``` +## Server-Side Rendering + +You can make authenticated requests both from the client and the server. However, you must use `useRequestFetch()` to make authenticated requests during SSR. + +```ts +// In your script setup +const { data } = await useRequestFetch()('/api/protected-endpoint'); +``` + +> There's [an open issue](https://github.com/nuxt/nuxt/issues/24813) to include credentials in `$fetch`/`useFetch` in Nuxt. + ## Configuration We leverage `runtimeConfig.session` to give the defaults option to [h3 `useSession`](https://h3.unjs.io/examples/handle-session). From 261f297e827e4fb88b9d40f718b7b6b0ce32bf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 10 Jun 2024 16:56:00 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e2d38420..a856eb24 100644 --- a/README.md +++ b/README.md @@ -208,14 +208,19 @@ export default defineNitroPlugin(() => { ## Server-Side Rendering -You can make authenticated requests both from the client and the server. However, you must use `useRequestFetch()` to make authenticated requests during SSR. +You can make authenticated requests both from the client and the server. However, you must use `useRequestFetch()` to make authenticated requests during SSR if you are not using `useFetch()` -```ts -// In your script setup -const { data } = await useRequestFetch()('/api/protected-endpoint'); +```vue + ``` -> There's [an open issue](https://github.com/nuxt/nuxt/issues/24813) to include credentials in `$fetch`/`useFetch` in Nuxt. +> There's [an open issue](https://github.com/nuxt/nuxt/issues/24813) to include credentials in `$fetch` in Nuxt. ## Configuration