erp-platform/ui/src/utils/hooks/useAuthority.ts
Sedat ÖZTÜRK e1a9562b22 init project
2025-05-06 09:45:49 +03:00

24 lines
540 B
TypeScript

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