Skip to content

Latest commit

 

History

History
103 lines (64 loc) · 1.49 KB

core.client.checkresources.md

File metadata and controls

103 lines (64 loc) · 1.49 KB

Home > @cerbos/core > Client > checkResources

Client.checkResources() method

Check a principal's permissions on a set of resources.

Signature:

checkResources(request: CheckResourcesRequest, options?: RequestOptions): Promise<CheckResourcesResponse>;

Parameters

Parameter

Type

Description

request

CheckResourcesRequest

options

RequestOptions

(Optional)

**Returns:**

Promise<CheckResourcesResponse>

Example

const decision = await cerbos.checkResources({
  principal: {
    id: "[email protected]",
    roles: ["USER"],
    attr: { tier: "PREMIUM" },
  },
  resources: [
    {
      resource: {
        kind: "document",
        id: "1",
        attr: { owner: "[email protected]" },
      },
      actions: ["view", "edit"],
    },
    {
      resource: {
        kind: "image",
        id: "1",
        attr: { owner: "[email protected]" },
      },
      actions: ["delete"],
    },
  ],
});

decision.isAllowed({
  resource: { kind: "document", id: "1" },
  action: "view",
}); // => true