import router from "@/router"; import { useAuth } from "@/stores/Auth/auth.store"; import type { App } from "vue"; const setupRouter = (app: App) => { router.beforeEach(async (to, from, next) => { if (to.meta.requireAuth || to.meta.onlyGuest) { const authStore = useAuth(); await authStore.getUser(); if (authStore.isAuthenticated && to.meta.requireAuth) { next(); } else if (!authStore.isAuthenticated && to.meta.onlyGuest) { next(); } else if (authStore.isAuthenticated && to.meta.onlyGuest) { next({ name: "dashboard" }); } else { next({ name: "login" }); } } next(); }); app.use(router); }; export default setupRouter;