Skip to content

Components · Reference

Permission guard

Show interface controls only when a project action is granted.

Preview

The report is visible.

Usage

tsx
import { HasPermission } from "@krak-stack/auth/has-permission/react";
import type { ReactNode } from "react";

export const PublishControl = ({
  children,
  permissions,
}: {
  children: ReactNode;
  permissions: readonly string[];
}) => (
  <HasPermission permission="report:publish" permissions={permissions}>
    {children}
  </HasPermission>
);

The React guard reads the active organization’s grants from KrakstackAuthProvider unless you pass permissions explicitly. In Effect UI, pass the effective project actions from your host as permissions and the gated view as the content slot.

This guard only controls presentation. Enforce the same permission independently on every protected server endpoint.