forked from baron/baron-sso
30 lines
611 B
TypeScript
30 lines
611 B
TypeScript
import type React from "react";
|
|
import {
|
|
type TenantPermissionKey,
|
|
useTenantPermission,
|
|
} from "../hooks/useTenantPermission";
|
|
|
|
interface TenantPermissionGuardProps {
|
|
tenantId: string;
|
|
relation: TenantPermissionKey;
|
|
fallback?: React.ReactNode;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export function TenantPermissionGuard({
|
|
tenantId,
|
|
relation,
|
|
fallback = null,
|
|
children,
|
|
}: TenantPermissionGuardProps) {
|
|
const { hasPermission, isLoading } = useTenantPermission(tenantId);
|
|
|
|
if (isLoading) return null;
|
|
|
|
if (!hasPermission(relation)) {
|
|
return <>{fallback}</>;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
}
|