import { createRouter, createWebHistory } from 'vue-router' import { useUserStore } from '@/stores/user' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/', name: 'index', component: () => import('../views/index.vue') }, { path: '/files', name: 'files', component: () => import('../views/files.vue'), } ] }) router.beforeEach(async (to, from, next) => { const userStore = useUserStore() // Initialize user state if not already initialized if (!userStore.user && localStorage.getItem('authToken')) { await userStore.initialize() } if (to.matched.some((record) => record.meta.requiresAuth) && !userStore.isAuthenticated) { next({ name: 'login', query: { redirect: to.fullPath } }) } else { next() } }) export default router