Files
lingxi-web/src/hooks/usePermission.ts
T

13 lines
427 B
TypeScript

import { useAuthStore } from '@/app/store/auth'
import { ROLE_PERMISSIONS, type Permission, type RoleKey } from '@/config/roles'
export function usePermission() {
const role = useAuthStore((s) => s.user?.role ?? 'viewer') as RoleKey
const perms = ROLE_PERMISSIONS[role] ?? []
return {
role,
can: (p: Permission) => perms.includes(p),
canAny: (...ps: Permission[]) => ps.some((p) => perms.includes(p)),
}
}