Authorization and Permissions (Client-Side)
The Authorization namespace in @serenity-is/corelib provides client-side permission checks and user-state accessors. These are intended for UI gating only — always enforce permissions on the server side as well.
Checking Permissions
hasPermission (synchronous)
import { Authorization } from "@serenity-is/corelib";
if (Authorization.hasPermission("Administration:General")) {
// show admin UI
}
hasPermissionAsync (recommended)
Prefer the async variant in new code — it awaits the UserData script instead of potentially blocking the UI thread:
if (await Authorization.hasPermissionAsync("Orders:View&Orders:Approve")) {
// show approve button
}
Permission Expressions
Permission checks support logical operators:
&— AND (all permissions required).|— OR (at least one required).&binds tighter than|, so"A&B|C"means(A AND B) OR C.
Special values:
| Value | Meaning |
|---|---|
"*" |
Always grants access. |
"" or "?" |
Only checks that a user is logged in. |
null / undefined |
Returns false. |
Users with IsAdmin are granted every permission.
User State
The Authorization namespace exposes the current user:
// Whether a user is logged in
const loggedIn = Authorization.isLoggedIn;
// The current user definition
const user = Authorization.userDefinition;
// user.Username, user.DisplayName, user.IsAdmin, user.Permissions
The UserDefinition interface describes the current user:
interface UserDefinition {
Username?: string;
DisplayName?: string;
IsAdmin?: boolean;
Permissions?: { [key: string]: boolean };
}
Permission-Based UI
A common pattern is to hide or disable UI elements based on permissions. For example, the EntityGrid disables the add button when the user lacks insert permission:
buttons.push({
title: this.getAddButtonCaption(),
action: 'add',
cssClass: 'add-button',
icon: faIcon("plus-circle", "green"),
hotkey: 'alt+n',
onClick: () => { this.addButtonClick(); },
disabled: () => !this.hasInsertPermission() || this.readOnly
});
What the Client May Load
Since 10.8.0 the permissions do not only hide UI: the server decides what the client can download.
- Form and columns scripts can require a permission, and the form/columns bundles contain only the scripts the user can
access, so the metadata of a page the user cannot open does not reach them. This is why a form that anonymous pages need
declares
Permission = "*"in its[FormScript]attribute, see Property item scripts. - Local texts are filtered by permission, so a visitor does not learn the structure of the application from the texts, see Filtering Local Texts by Permission.
- ES modules under the
esmfolders are served only to users who may load an entry point that imports them, see ESM Access Control.
A side effect is that localText may return a key for a text the user is not sent, and a type that the user cannot access may
not be registered on the client. Both are intended: the UI of that page should not be reachable in the first place.
Important: UI-Only Checks
Client-side permission checks are not security. They only control what the user sees and can click. The server must always re-validate permissions, because a malicious client can bypass any client-side check.
See Also
- Authorization (API reference) — the full
AuthorizationAPI. - UserDefinition (API reference) — the user definition type.
- EntityGrid CRUD — how grids use permissions.
- EntityDialog and CRUD Workflows — how dialogs use permissions.
- Frontend Framework Overview — the three client-side packages and how they fit together.