Gate a user action
A todo application needs to decide whether to show its create or edit control.
Kinde · Module
Checks whether the current user has a specified permission in the active organization. It returns the permission key, organization code, and a boolean access result.
In Kinde's React SDK, obtain getPermission from useKindeAuth and pass it a permission key such as read:todos. The asynchronous call evaluates the current user's permission for their active organization and returns an object containing the key, organization code, and whether access is granted.
const { getPermission } = useKindeAuth();
await getPermission(permissionKey);| Name | Type | Description |
|---|---|---|
permissionKey | string | Permission key to check, such as read:todos. |
A promise resolving to an object containing permissionKey, orgCode, and isGranted.
const { getPermission } = useKindeAuth();
const runAsyncFunction = async () => {
const permission = await getPermission("read:todos");
console.log(permission);
};
<button onClick={runAsyncFunction}>Get Permission</button>;Checks the signed-in user's access to the specified permission and returns its state.
A todo application needs to decide whether to show its create or edit control.
A frontend route should display content only to users with a required permission.
An organization-aware interface needs to report the permission context used for a decision.
getPermission checks one permission for the current user. In the React SDK it is called through useKindeAuth and resolves to an object with permissionKey, orgCode, and isGranted.
Follow-up: How would you inspect every permission instead? Use getPermissions, which returns the current organization's permission collection.
Pass the permission key as a string, for example read:todos. The call is asynchronous, so await its result before using the returned access state.
Follow-up: What should the UI do with isGranted? Use it to conditionally enable or render the protected action.
Permission values are tied to the organization the user is signed into. The result includes orgCode so the organization context can be identified.
Follow-up: Why does organization context matter? A user can have different permissions in different organizations, so checks must use the active organization.
useKindeAuthgetPermissionsProtectedRoutehas