Created
May 17, 2021 02:26
-
-
Save iskenxan/32848a242bce0cd13c9fd1b4f4168fce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function PermissionsGate({ | |
children, | |
RenderError = () => <></>, | |
errorProps = null, | |
scopes = [] | |
}) { | |
const { role } = useGetRole(); | |
const permissions = PERMISSIONS[role]; | |
const permissionGranted = hasPermission({ permissions, scopes }); | |
if (!permissionGranted && !errorProps) return <RenderError />; | |
if (!permissionGranted && errorProps) | |
return cloneElement(children, { ...errorProps }); | |
return <>{children}</>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment