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

This commit is contained in:
Daniel Roe 2024-07-03 12:43:59 +01:00 committed by GitHub
parent fb4d11d2b9
commit 421d100172
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

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
```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'))
}
}
})