refactor: code organization

This commit is contained in:
2024-10-23 15:23:33 +02:00
parent 018357c5ed
commit 5a32c96a88
29 changed files with 1134 additions and 615 deletions
+23
View File
@@ -0,0 +1,23 @@
import { Router } from 'vue-router';
import { useAuthStore } from './stores/auth.store';
export function createRouteGuard(router: Router) {
router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
console.log(to);
if (to.meta.protected && !authStore.user && !window.localStorage.getItem('user')) {
next('/login');
return;
}
if (to.meta.loginPage && window.localStorage.getItem('user')) {
next('/');
return;
}
next();
});
}