docs: update example to use nuxtApp.runWithContext (#28000)

This commit is contained in:
Daniel Roe 2024-07-03 12:43:59 +01:00
parent e6109b2266
commit b7c60bf829
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -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 - If the API responds with a `401` status code, we redirect the user to the `/login` page
```ts [plugins/api.ts] ```ts [plugins/api.ts]
export default defineNuxtPlugin(() => { export default defineNuxtPlugin((nuxtApp) => {
const { session } = useUserSession() const { session } = useUserSession()
const api = $fetch.create({ const api = $fetch.create({
@ -43,7 +43,7 @@ export default defineNuxtPlugin(() => {
}, },
async onResponseError({ response }) { async onResponseError({ response }) {
if (response.status === 401) { if (response.status === 401) {
await navigateTo('/login') await nuxtApp.runWithContext(() => navigateTo('/login'))
} }
} }
}) })