⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
'use client';
import type { ReactNode } from 'react';
import { useTranslations } from 'next-intl';
import { usePermissions } from '@/hooks/usePermissions';
import type { PermissionAction, PermissionResource } from '@/lib/api/endpoints/roles';
// Gates a whole page or section: renders children when the current user may perform
// `action` on `resource`, otherwise a short access message. The API enforces the
// same check per request, so this is UX (a clear notice instead of a failed
// request), not a security boundary.
export default function RequirePermission({
resource,
action,
message,
children,
}: {
resource: PermissionResource;
action: PermissionAction;
message?: string;
children: ReactNode;
}) {
const t = useTranslations('common');
const { can } = usePermissions();
if (!can(resource, action)) {
return <p className="text-sm text-muted-foreground">{message ?? t('noSectionAccess')}</p>;
}
return <>{children}</>;
}