import { createRouter, createWebHistory } from 'vue-router' import { useAuthStore } from '@/stores/auth' const router = createRouter({ history: createWebHistory(), routes: [ { path: '/login', name: 'login', component: () => import('@/pages/auth/LoginPage.vue'), meta: { public: true }, }, { path: '/auth/callback', name: 'oauth-callback', component: () => import('@/pages/auth/OAuthCallback.vue'), meta: { public: true }, }, { path: '/', redirect: '/dashboard', }, { path: '/dashboard', name: 'dashboard', component: () => import('@/pages/dashboard/DashboardPage.vue'), meta: { title: 'Dashboard' }, }, ], }) router.beforeEach((to) => { const auth = useAuthStore() if (!to.meta.public && !auth.isAuthenticated) { return { name: 'login', query: { redirect: to.fullPath } } } if (to.name === 'login' && auth.isAuthenticated) { return { name: 'dashboard' } } }) export default router