fix(frontend): update router guard API
All checks were successful
deploy-socialize / image (push) Successful in 53s
deploy-socialize / deploy (push) Successful in 18s

This commit is contained in:
2026-05-07 12:34:32 -04:00
parent 0521d91240
commit 918136aae2

View File

@@ -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;