fix: enforce vue route permissions
This commit is contained in:
1 parent
f07a61f3a8
commit
279cf51068
1 file changed
+16
-6
@@ -31,11 +31,11 @@ const router = createRouter({
|
||||
name: "admin",
|
||||
component: AdminLayout,
|
||||
children: [
|
||||
{ path: "dashboard", name: "dashboard", component: DashboardPage },
|
||||
{ path: "home", name: "home", component: HomePage },
|
||||
{ path: "play", name: "play", component: WanfaPage },
|
||||
{ path: "concierge", name: "concierge", component: ConciergePage },
|
||||
{ path: "leads", name: "leads", component: LeadsPage },
|
||||
{ path: "dashboard", name: "dashboard", component: DashboardPage, meta: { permission: "admin:dashboard" } },
|
||||
{ path: "home", name: "home", component: HomePage, meta: { permission: "admin:site-config" } },
|
||||
{ path: "play", name: "play", component: WanfaPage, meta: { permission: "admin:wanfa:read" } },
|
||||
{ path: "concierge", name: "concierge", component: ConciergePage, meta: { permission: "admin:concierge:read" } },
|
||||
{ path: "leads", name: "leads", component: LeadsPage, meta: { permission: "admin:leads:read" } },
|
||||
{ path: "system/:resource", name: "system-resource", component: SystemResourcePage },
|
||||
{ path: "", redirect: "/dashboard" },
|
||||
],
|
||||
@@ -72,7 +72,17 @@ router.beforeEach(async (to) => {
|
||||
await auth.bootstrap();
|
||||
if (!auth.isAuthenticated) return { name: "login", query: { redirect: to.fullPath } };
|
||||
registerDynamicRoutes();
|
||||
const permission = to.meta.permission;
|
||||
const systemPermissions: Record<string, string> = {
|
||||
users: "system:user:read",
|
||||
roles: "system:role:read",
|
||||
menus: "system:menu:read",
|
||||
depts: "system:dept:read",
|
||||
};
|
||||
const permission = typeof to.meta.permission === "string"
|
||||
? to.meta.permission
|
||||
: to.name === "system-resource"
|
||||
? systemPermissions[String(to.params.resource)]
|
||||
: undefined;
|
||||
if (typeof permission === "string" && !auth.hasPermission(permission)) return { name: "not-found" };
|
||||
return true;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user