@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
24 lines • 882 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useMatches } from "react-router-dom";
import { ForbiddenSection } from "../ForbiddenSection";
import { useAccess } from "../context/access/Access";
function hasProp(data, prop) {
return prop in data;
}
export const AuthWall = ({ children }) => {
const matches = useMatches();
const { hasAccess } = useAccess();
const permissionNeeded = matches.flatMap(({ handle }) => {
if (typeof handle !== "object" ||
handle === null ||
!hasProp(handle, "access")) {
return [];
}
if (Array.isArray(handle.access)) {
return handle.access;
}
return [handle.access];
});
return hasAccess(...permissionNeeded) ? (children) : (_jsx(ForbiddenSection, { permissionNeeded: permissionNeeded }));
};
//# sourceMappingURL=AuthWall.js.map