Official React context provider, authentication hooks, and declarative RBAC permission gates for seamless integration with React, Next.js, and Remix applications.
Installation
Install the zero-dependency SDK package via npm or pnpm:
bash
npm install @hvt/sdk
1. Provider Setup
Wrap your application root with <HVTProvider> and pass a configured HVTClient instance:
Use <PermissionGate> to conditionally render UI controls based on project-scoped permission slugs:
tsx
import { PermissionGate } from'@hvt/sdk/react';
exportfunctionOrderPanel() {
return (
<div><h2>Order Management</h2>
{/* Renders only if user has orders.create */}
<PermissionGatepermission="orders.create"fallback={<pclassName="text-muted">You do not have permission to place orders.</p>}
>
<buttononClick={handleCreateOrder}>Place New Order</button></PermissionGate>
{/* Renders if user has either of these permissions */}
<PermissionGateanyOf={['orders.export', 'admin.manage']}><buttononClick={handleExportCSV}>Export Orders CSV</button></PermissionGate></div>
);
}
4. Declarative Role Gating
Use <RoleGate> to gate sections based on project role assignments:
tsx
import { RoleGate } from'@hvt/sdk/react';
exportfunctionMerchantPortal() {
return (
<RoleGaterole="seller"fallback={<p>Become a seller to view store analytics.</p>}>
<StoreAnalyticsDashboard /></RoleGate>
);
}