Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Last active May 17, 2021 21:05
Show Gist options
  • Save iskenxan/56f82b698ceba99012243f2b62c54870 to your computer and use it in GitHub Desktop.
Save iskenxan/56f82b698ceba99012243f2b62c54870 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 />;
return <>{children}</>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment