Skip to content
0

katanakit-js / useCan

Function: useCan() ​

ts
function useCan(subject, capability): boolean;

Defined in: src/core/services/access.service.ts:415

Whether the subject may perform a capability. Any of the subject's roles granting the capability (directly or by inheritance) is enough.

Parameters ​

ParameterType
subject{ [key: string]: unknown; id: string | number; roles: string[]; }
subject.idstring | number
subject.rolesstring[]
capabilitystring

Returns ​

boolean

Example ​

ts
useCan({ id: 1, roles: ["author"] }, "content:publish"); // false
useCan({ id: 1, roles: ["author"] }, "content:create");  // true
useCan({ id: 2, roles: ["editor"] }, "content:create");  // true (inherits author)
useCan({ id: 3, roles: [] }, "conversations:use");       // false

Released under the MIT License.