Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions skills/objectui/guides/auth-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,20 @@ guide does not govern it; the two look alike and are unrelated.

### usePermissions hook

```typescript
<!-- os:check -->
```tsx
import { usePermissions } from '@object-ui/permissions';
import { Button } from '@object-ui/components';

function ContactActions({ contact }) {
const { check, checkField, getFieldPermissions, getRowFilter } = usePermissions();
function ContactActions({ contact }: { contact: { salary?: number } }) {
const { can, checkField, getFieldPermissions, getRowFilter } = usePermissions();

const canEdit = check('contacts', 'update', contact);
const canDelete = check('contacts', 'delete', contact);
// Gate on `can`, which answers a boolean. `check` answers `{ allowed, … }`, and
// an object is truthy, so gated on it both buttons render for a denied user
// too; its `record` argument reads no field of the record, so none is passed.
// `: boolean` is what makes a `check(...)` here fail to compile.
const canEdit: boolean = can('contacts', 'update');
const canDelete: boolean = can('contacts', 'delete');
const canSeeSalary = checkField('contacts', 'salary', 'read');

return (
Expand Down
Loading