import { createRouter, createWebHistory } from 'vue-router' import { useAuthStore } from '../stores/auth' const routes = [ { path: '/login', name: 'Login', component: () => import('../views/LoginView.vue'), meta: { public: true }, }, { path: '/', component: () => import('../layouts/MainLayout.vue'), children: [ { path: '', name: 'Dashboard', component: () => import('../views/dashboard/DashboardView.vue') }, { path: 'iam-users', name: 'IAMUsers', component: () => import('../views/iam/IAMUserList.vue') }, { path: 'billing', name: 'Billing', component: () => import('../views/billing/BillingView.vue') }, { path: 'alerts', name: 'Alerts', component: () => import('../views/alerts/AlertList.vue') }, { path: 'settings', name: 'Settings', component: () => import('../views/settings/SettingsView.vue') }, ], }, ] const router = createRouter({ history: createWebHistory(), routes, }) router.beforeEach((to) => { const auth = useAuthStore() if (!to.meta.public && !auth.isLoggedIn) { return '/login' } }) export default router