diff --git a/docs/2.guide/4.recipes/3.custom-usefetch.md b/docs/2.guide/4.recipes/3.custom-usefetch.md index 0aa0162db0..9ada89255a 100644 --- a/docs/2.guide/4.recipes/3.custom-usefetch.md +++ b/docs/2.guide/4.recipes/3.custom-usefetch.md @@ -24,7 +24,7 @@ Let's pretend here that: - If the API responds with a `401` status code, we redirect the user to the `/login` page ```ts [plugins/api.ts] -export default defineNuxtPlugin(() => { +export default defineNuxtPlugin((nuxtApp) => { const { session } = useUserSession() const api = $fetch.create({ @@ -43,7 +43,7 @@ export default defineNuxtPlugin(() => { }, async onResponseError({ response }) { if (response.status === 401) { - await navigateTo('/login') + await nuxtApp.runWithContext(() => navigateTo('/login')) } } })