diff --git a/frontend/src/router/router.js b/frontend/src/router/router.js index 6ef7c3aa..520a1ce0 100644 --- a/frontend/src/router/router.js +++ b/frontend/src/router/router.js @@ -244,30 +244,32 @@ const router = createRouter({ }); // Navigation guards -router.beforeEach((to, from, next) => { +router.beforeEach((to) => { const authStore = useAuthStore(); if (to.matched.some(record => record.meta.requiresAuth)) { if (!authStore.isAuthenticated) { - next({ + return { name: 'login', query: { returnUrl: to.fullPath }, - }); - } else { - const requiredRoles = to.matched.flatMap(record => record.meta.roles ?? []); - if (requiredRoles.length > 0 && !authStore.hasAnyRole(requiredRoles)) { - next({ name: 'dashboard' }); - return; - } - - next(); + }; } - } else if (to.matched.some(record => record.meta.notAuthenticated)) { - if (authStore.isAuthenticated) next({ name: 'dashboard' }); - else next(); - } else { - next(); + + const requiredRoles = to.matched.flatMap(record => record.meta.roles ?? []); + if (requiredRoles.length > 0 && !authStore.hasAnyRole(requiredRoles)) { + return { name: 'dashboard' }; + } + + return true; } + + if (to.matched.some(record => record.meta.notAuthenticated)) { + return authStore.isAuthenticated + ? { name: 'dashboard' } + : true; + } + + return true; }); export default router;