Skip to content

can

can(grants, action, table): boolean

Defined in: packages/permissions/src/can.ts:29

Checks whether a set of resolved grants permits a specific action on a table.

Unlike checkPermissions (which takes a role string and the full permissions object), can works directly with the user’s resolved grants — the same grants available in loaders, actions, and client-side via useActions.

Grant[]

The user’s resolved permission grants.

PermissionAction

The permission action to check (e.g., "create", "read").

object

The Drizzle table object to check against.

boolean

true if any grant permits the action on the table.

import { can } from "@cfast/permissions";
// In a loader
if (!can(ctx.auth.grants, "create", posts)) {
throw redirect("/");
}
// In a component
{can(grants, "update", posts) && <Button>Edit</Button>}