export default defineNuxtRouteMiddleware((to) => { // Allowlist: routes that should always be accessible before setup if ( to.path === "/coop-planner" || to.path === "/coop-builder" || to.path === "/wizards" || to.path.startsWith("/templates") || to.path.startsWith("/coach") || to.path.startsWith("/api/") ) { return; } // Only guard core dashboards until setup is complete const protectedRoutes = new Set([ "/dashboard", "/dashboard-simple", "/budget", "/mix", "/cash", ]); if (!protectedRoutes.has(to.path)) { return; } // Use actual store state to determine whether setup is complete const membersStore = useMembersStore(); const policiesStore = usePoliciesStore(); const streamsStore = useStreamsStore(); const coopStore = useCoopBuilderStore?.(); // Legacy stores OR new coop builder store (either is enough) const legacyComplete = membersStore.isValid && policiesStore.isValid && streamsStore.hasValidStreams; const coopComplete = Boolean( coopStore && Array.isArray(coopStore.members) && coopStore.members.length > 0 && Array.isArray(coopStore.streams) && coopStore.streams.length > 0 ); const setupComplete = legacyComplete || coopComplete; if (!setupComplete) { return navigateTo("/coop-planner"); } });