scute.authz answers what the UI should show for the signed-in user. The app must allow client checks (the client_checks authorization setting). Your backend still checks before the real action with admin.authzCheck, which is also where a step-up verification is redeemed.
Check one permission#
const { data, error } = await scute.authz.can("edit", "document:42");if (data?.allowed) showEditButton();can(action, resource?, context?). resource is a type ("document"), a type and key ("document:42"), or { type, key?, attributes? }.
The answer (AuthzDecision):
| Field | Meaning |
|---|---|
| decision | "allow", "deny", "allow_with_step_up" or "allow_with_approval" |
| allowed | true only for "allow". A step-up or approval answer is false until it is satisfied. |
| reason | Machine-readable reason |
| permission | The permission slug, such as "document:edit" |
| roles | Roles that granted it |
| path | For roles held through relationships: { instance, role, via? }[] |
| conditions | Conditions that held, for conditional grants |
| step_up | { method, ttl?, authorizes_action, error?, detail? } when a fresh verification is needed |
| approval | { permission, resource?, error? } when a reviewer's approval is needed |
| explanation | Plain-language reason |
Many checks#
const { data } = await scute.authz.canMany([ { action: "edit", resource: "document:42" }, { action: "delete", resource: "document:42" },]);// data: AuthzDecision[], in the same orderUp to 100 checks per call.
Everything the user can do#
const { data } = await scute.authz.permissions(); // app-wideconst { data: onDoc } = await scute.authz.permissions("document:42");// { user_id, roles, permissions, step_up, conditional?, verified_until?, resource?, resource_roles? }Access requests#
The app must allow them (the access_requests setting). A user asks for a role, or for approval of one operation:
await scute.authz.requestAccess({ role: "editor", reason: "Quarterly report" });await scute.authz.requestAccess({ role: "editor", resource: "document:42", duration: 3600 });await scute.authz.requestAccess({ action: "refund", resource: "invoice:981", reason: "Customer call" });const { data: mine } = await scute.authz.myRequests("pending");await scute.authz.cancelRequest(mine[0].id);Reviewers see and decide pending requests:
const { data: pending } = await scute.authz.reviews(); // empty when the user is not a reviewerawait scute.authz.approveRequest(pending[0].id, "OK for this quarter");await scute.authz.denyRequest(pending[1].id);A request (AuthzAccessRequest) has id, kind ("role" or "operation"), user_id, status ("pending", "approved", "denied", "cancelled", "expired", "used"), role, resource_role, resource, permission, reason, duration_seconds, expires_at, decided_at, decided_by, decision_note, used_at and created_at.
An approved operation request is used once: the backend passes its ID as approval to admin.authzCheck.
For React, useCan and usePermissions wrap these calls. See Authorization hooks.