Skip to content

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.

TSubjects extends Record<string, SubjectEntry>

TSubject extends string

TData extends object

HasPermissionProps<TSubjects, TSubject, TData>

boolean

true when the action is permitted for the caller.

HasPermissionProps

When throwOnDenied is true and access is denied — carries resource and action.

hasPermission({ access, user, resource: "posts", action: "update" }); // boolean
hasPermission({ access, user, resource: "posts", action: "delete",
data: post, throwOnDenied: true }); // throws VexAccessError on deny