Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Created May 17, 2021 02:26
Show Gist options
  • Save iskenxan/32848a242bce0cd13c9fd1b4f4168fce to your computer and use it in GitHub Desktop.
Save iskenxan/32848a242bce0cd13c9fd1b4f4168fce to your computer and use it in GitHub Desktop.
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