@humano/frontend-permissions
v0.2.1
Published
React hooks and small UI helpers for view/action permissions. No data layer included.
Maintainers
Readme
@humano/frontend-permissions
Small, data-agnostic building blocks for view/action permissions in React 18/19:
usePermissionCheckerFromFn— memoize(viewId, action) => booleanuseViewPermissions—canEditar(),can("custom"), …PermissionGate/useGuardedAction— UIfilterMenuByRouteOptions/getFirstAllowedRoute— filter nav trees and pick a default routehasPathAccessInOptions/matchPathToOptions— path matching (pass your router basename explicitly; no default is assumed)
No HTTP client, no auth provider, no hardcoded host or product routes — bring your own.
Install
npm install @humano/frontend-permissions
# or: pnpm add / yarn addPeer: react ^18 || ^19.
Imports
Recommended root import:
import {
usePermissionCheckerFromFn,
useViewPermissions,
PermissionGate,
filterMenuByRouteOptions,
} from '@humano/frontend-permissions';Subpath imports still work:
import { useViewPermissions } from '@humano/frontend-permissions/useViewPermissions';Menu filtering
- Get allowed route keys from your backend (e.g. string list).
- Set
applicationBasePathto the same value as your React Routerbasename(or""). - Call
filterMenuByRouteOptions(items, allowedPaths, { applicationBasePath, isDevelopment }).
Publish (maintainers)
From a clone of the package:
cd packages/frontend-permissions
npm run build
npm publish --access public
# scope must match your npm organization; see package "name" fieldLicense
MIT – see LICENSE.
