mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 05:28:13 +00:00
21 lines
483 B
TypeScript
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();
|
|
});
|
|
}
|