mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 05:28:13 +00:00
refactor: code organization
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user