N
Nuxt2y ago
Mole

Can nuxt 3 middleware be asynchronous?

I am trying the below trivial example with one await and navigateTo, resulting in error:
[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.
[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.
const to = await getRouteTo()
return navigateTo(to)
const to = await getRouteTo()
return navigateTo(to)
1 Reply
Mole
MoleOP2y ago
Real life example would be auth middleware checking for permissions only after protected route is visited; if permissions are insufficient, redirect user away.

Did you find this page helpful?