Skip to content

@serenity-is/corelib / Authorization / hasPermissionAsync

Function: hasPermissionAsync()

hasPermissionAsync(permission): Promise<boolean>

Defined in: src/base/authorization.ts:88

Asynchronously checks whether the current user has the specified permission.

Parameters

permission

string

Permission key or expression with &/| operators, e.g. "A&B|C". null/undefined returns false; "*" returns true; "" or "?" returns whether the user is logged in.

Returns

Promise<boolean>

Promise that resolves to true if the user has the permission (or is an admin), otherwise false.

Remarks

Preferred over Authorization.hasPermission because it awaits UserData via getRemoteDataAsync instead of potentially blocking the UI thread. Still UI-only — enforce permissions server-side as well.

Examples

if (await Authorization.hasPermissionAsync("Administration:General")) { ... }
await Authorization.hasPermissionAsync("A&B|C"); // true if (A and B) or C