/** * Auth Middleware * * Protects routes that require authentication. * Redirects to login if user is not authenticated. * * Note: Auth state is initialized by the auth.client.ts plugin before this middleware runs. */ import { useAuthStore } from '~/store/auth' export default defineNuxtRouteMiddleware((to, from) => { const authStore = useAuthStore() console.log('[Auth Middleware]', { path: to.path, isAuthenticated: authStore.isAuthenticated, hasUser: !!authStore.currentUser, }) // Allow access if authenticated if (authStore.isAuthenticated) { return } // Redirect to login with return URL console.log('[Auth Middleware] Redirecting to login') return navigateTo({ path: '/auth/login', query: { redirect: to.fullPath }, }) })