Middleware
Demonstrates the guest middleware and explains enableGlobalAuthMiddleware.
guest middleware
This page declares definePageMeta({ middleware: 'guest' }). The guest middleware is a no-op by itself - it exists as an explicit opt-out marker for when enableGlobalAuthMiddleware is enabled.
When enableGlobalAuthMiddleware: true is set in nuxt.config.ts, every route requires authentication by default. Marking a page with guest exempts it from that check, keeping it publicly accessible.
// nuxt.config.ts
directus: {
auth: {
enableGlobalAuthMiddleware: true, // protect all routes
},
}
// any public page
definePageMeta({ middleware: 'guest' })nuxt.config.ts
This playground has
enableGlobalAuthMiddleware: false (the default), so guest is declared here for demonstration purposes only - it has no effect in the current configuration. auth middleware
The inverse: add middleware: 'auth' to any page to protect it individually. The Dashboard page in this playground uses this pattern. When a logged-out user visits it they are redirected to /auth/login?redirect=/dashboard and returned after login.