Files
station-manager-2.0/src/routeGuard.ts
T
2025-01-26 18:05:03 +01:00

21 lines
483 B
TypeScript

import { Router } from 'vue-router';
import { useAuthStore } from './stores/auth.store';
export function createRouteGuard(router: Router) {
router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
if (to.meta.protected && !authStore.user && !window.localStorage.getItem('user')) {
next('/login');
return;
}
if (to.meta.loginPage && window.localStorage.getItem('user')) {
next('/');
return;
}
next();
});
}