hasPermission
hasPermission<
TSubjects,TSubject,TData>(props):boolean
Defined in: packages/core/src/access/hasPermission.ts:79
Resolves runtime role-based access for a single subject + action, merging every role the user holds into one decision.
This is the single runtime entry point — every server API guard, admin panel gate, and custom-subject check calls it; the resolution helpers below are module-private.
Resolution, per role, first hit wins: subject boolean shorthand → explicit
action key → subject-level WILDCARD_KEY → role-level WILDCARD_KEY
(undeclared subjects only) → defaultPermissionMode. Roles then OR-merge:
any role allowing allows.
Type Parameters
Section titled “Type Parameters”TSubjects
Section titled “TSubjects”TSubjects extends Record<string, SubjectEntry>
TSubject
Section titled “TSubject”TSubject extends string
TData extends object
Parameters
Section titled “Parameters”HasPermissionProps<TSubjects, TSubject, TData>
Returns
Section titled “Returns”boolean
true when the action is permitted for the caller.
Throws
Section titled “Throws”When throwOnDenied is true and access is denied —
carries resource and action.
Example
Section titled “Example”hasPermission({ access, user, resource: "posts", action: "update" }); // booleanhasPermission({ access, user, resource: "posts", action: "delete", data: post, throwOnDenied: true }); // throws VexAccessError on deny