import { createRouter, createWebHistory } from "vue-router"; import { useAuthStore } from "@/stores/auth.store.ts"; const routes = [ { path: '/', name: 'Dashboard', component: () => import('../pages/Backoffice.vue'), }, { path: '/login', name: 'Login', component: () => import('../pages/Login.vue'), }, ]; const router = createRouter({ history: createWebHistory(), routes }); export default router; /** * Redirect to login page if unauthenticated */ router.beforeEach(async (to) => { // redirect to login page if not logged in and trying to access a restricted page const publicPages = ['/login']; const authRequired = !publicPages.includes(to.path); const auth = useAuthStore(); if (authRequired && !auth.userData) { auth.returnUrl = to.fullPath; return '/login'; } });