MDK Logo
ReferenceUIHooks

Permission Hooks

Permission and access control hooks

Hooks for checking permissions and managing access control.

Package

@tetherto/mdk-react-adapter

Hooks

@tetherto/mdk-react-adapter

Check a permission

import { useCheckPerm } from '@tetherto/mdk-react-adapter'

When to use useCheckPerm

Use useCheckPerm for a single reactive permission, write-access or capability gate in a React component. It reads the current permissions from the same auth store exposed by useAuth.

useCheckPerm example

import { useCheckPerm } from '@tetherto/mdk-react-adapter'
import { Button } from '@tetherto/mdk-react-devkit'

function EditUsersButton() {
  const canEditUsers = useCheckPerm({ perm: 'users:write' })
  return canEditUsers ? <Button>Edit users</Button> : null
}
@tetherto/mdk-react-adapter

useCheckPerm

Hook to check if the current user has a specific permission. Reads permissions from the headless authStore via @tetherto/mdk-react-adapter.

({ perm, write, cap }: PermissionCheck) => boolean

useHasPerms

Hook returning a permission-check callback bound to the current authStore.permissions.

() => ((req: PermissionRequest) => boolean)

useIsFeatureEditingEnabled

Hook to check if the current user has the capability to edit feature flags.

() => boolean

On this page