export default defineNuxtRouteMiddleware(async (to) => { const auth = useAuthStore() const isLogin = to.path === '/login' if (!auth.checked) { await auth.ensureSession() } if (!isLogin && !auth.isAuthenticated) { return navigateTo('/login') } const isClientOnly = auth.isAuthenticated && auth.user?.roles?.includes('ROLE_CLIENT') && !auth.user?.roles?.includes('ROLE_ADMIN') if (isLogin && auth.isAuthenticated) { return navigateTo(isClientOnly ? '/portal' : '/') } const isProfileRoute = to.path === '/profile' if (isClientOnly && !to.path.startsWith('/portal') && !isProfileRoute) { return navigateTo('/portal') } })