Role.create()

Create a role.

Signature

Role.create(data: {*: Any}): Role

Description

The Role.create() method creates a role with the provided data.

Only resources with an admin key can create or manage user-defined roles. Roles are created in the current database. To establish the same roles throughout a database hierarchy, you must separately create identical roles in each child database that requires them.

The maximum number of overlapping roles is 64. Trying to create more overlapping roles result in an error.

Parameters

Parameter Type Required Description

data

Object

Yes

Object describing the role.

data fields

Name Type Required Description

name

String

Yes

A unique name.

membership

Array

One or more membership configuration objects.
See Membership configuration object

privileges

Array

Yes

One or more privilege configuration objects.
See Privilege configuration object

data

Object

User-defined metadata that stores supplemental information.

Return value

Type Description

Role

A Role document.

Examples

Role.create({
    name: "mgmtTeam",
    membership: [
    {resource: "People"}],
    privileges: [{
      resource: "CoffeeBean",
      actions: {
        read: true
      }
    }, {
      resource: "Customers",
      actions: {
        create: true
      }
    }],
    data: {
      custom: "some data"
    }
  })
{
  name: "mgmtTeam",
  coll: Role,
  ts: Time("2023-07-27T21:59:03.480Z"),
  privileges: [
    {
      resource: "CoffeeBean",
      actions: {
        read: true
      }
    },
    {
      resource: "Customers",
      actions: {
        create: true
      }
    }
  ],
  membership: [
    {
      resource: "People"
    }
  ],
  data: {
    custom: "some data"
  }
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!