Is there a way to access the req object in Nuxt3 Route Middleware similar to how we do it in Nuxt2 middleware?
Let's compare the code:
Nuxt2
// middleware/auth.js
export default ({ store, req }) => {
if (req) {
store.dispatch('auth/initAuth', { req })
}
}
Nuxt3
// middleware/auth.ts
export default defineNuxtRouteMiddleware((to, from) => {
if (to.params.id === '1') {
return abortNavigation()
}
return navigateTo('/')
})
In Nuxt 3 Middleware, we seem to only have access to to
and from
params. How can I obtain the req
object like in Nuxt2?