import React from "react"; import PropTypes from "prop-types"; import { Typography, Card, CardBody } from "@material-tailwind/react"; import { useAuth } from "@/components/AuthProvider.jsx"; export function PermissionGate({ permission, requiredLevel = "full", loadingFallback = null, children, }) { const { initialized, loading, hasPermission } = useAuth(); if (!permission) { return children; } if (!initialized || loading) { return ( loadingFallback ?? (
Berechtigungen werden geladen …
) ); } if (hasPermission(permission, requiredLevel)) { return children; } return (
Kein Zugriff auf diesen Bereich Für diese Funktion wird die Berechtigung {permission} benötigt.
); } PermissionGate.propTypes = { permission: PropTypes.string, requiredLevel: PropTypes.string, loadingFallback: PropTypes.node, children: PropTypes.node.isRequired, }; export default PermissionGate;