ff-admin/src/router/adminGuard.ts

25 lines
660 B
TypeScript
Raw Normal View History

2024-09-01 19:19:48 +02:00
import NProgress from "nprogress";
2024-09-17 16:44:02 +02:00
import { useAbilityStore } from "@/stores/ability";
import { useNavigationStore } from "@/stores/admin/navigation";
2024-09-01 19:19:48 +02:00
export async function abilityAndNavUpdate(to: any, from: any, next: any) {
NProgress.start();
const ability = useAbilityStore();
const navigation = useNavigationStore();
let type = to.meta.type;
let section = to.meta.section;
let module = to.meta.module;
navigation.activeNavigation = to.name.split("-")[1];
navigation.activeLink = to.name.split("-")[2];
if (ability.can(type, section, module)) {
NProgress.done();
next();
} else {
NProgress.done();
next(false);
}
}