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 // Navigation guards
router.beforeEach((to, from, next) => { router.beforeEach((to) => {
const authStore = useAuthStore(); const authStore = useAuthStore();
if (to.matched.some(record => record.meta.requiresAuth)) { if (to.matched.some(record => record.meta.requiresAuth)) {
if (!authStore.isAuthenticated) { if (!authStore.isAuthenticated) {
next({ return {
name: 'login', name: 'login',
query: { returnUrl: to.fullPath }, 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(); const requiredRoles = to.matched.flatMap(record => record.meta.roles ?? []);
if (requiredRoles.length > 0 && !authStore.hasAnyRole(requiredRoles)) {
return { name: 'dashboard' };
} }
} else if (to.matched.some(record => record.meta.notAuthenticated)) {
if (authStore.isAuthenticated) next({ name: 'dashboard' }); return true;
else next();
} else {
next();
} }
if (to.matched.some(record => record.meta.notAuthenticated)) {
return authStore.isAuthenticated
? { name: 'dashboard' }
: true;
}
return true;
}); });
export default router; export default router;