erp-platform/ui/src/utils/hooks/useAuthority.ts

25 lines
540 B
TypeScript
Raw Normal View History

2025-05-06 06:45:49 +00:00
import { useMemo } from 'react'
import isEmpty from 'lodash/isEmpty'
function useAuthority(
userAuthority: string[] = [],
authority: string[] = [],
emptyCheck = false
) {
const roleMatched = useMemo(() => {
return authority.some((role) => userAuthority.includes(role))
}, [authority, userAuthority])
if (
isEmpty(authority) ||
isEmpty(userAuthority) ||
typeof authority === 'undefined'
) {
return !emptyCheck
}
return roleMatched
}
export default useAuthority