Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

Role.byName()

Learn: Roles

Get a user-defined role by its name.

Signature

Role.byName(name: String) => NamedRef<Role>

Description

Gets a user-defined role, represented as an Role document, by its name.

Role documents are FQL versions of a database’s FSL role schema. See Roles.

Staged schema

If a database has staged schema, this method interacts with the database’s staged schema, not the active schema.

Parameters

Parameter Type Required Description

name

String

true

name of the Role document to retrieve.

Return value

Type Description

NamedRef<Role>

Resolved reference to the Role document. Can resolve to an existing document or a NullDoc.

Examples

Role.byName("manager")
{
  name: "manager",
  coll: Role,
  ts: Time("2099-10-28T16:01:40.805Z"),
  privileges: [
    {
      resource: "OrderItem",
      actions: {
        create: true,
        read: true,
        write: true,
        delete: true
      }
    },
    {
      resource: "Customer",
      actions: {
        read: true
      }
    },
    {
      resource: "Manager",
      actions: {
        read: "(doc) => Query.identity() == doc && Date.today().dayOfWeek < 6"
      }
    },
    {
      resource: "getOrCreateCart",
      actions: {
        call: true
      }
    },
    {
      resource: "checkout",
      actions: {
        call: <<-END
          (args) => {
            let order = Order.byId(args[0])!
            order?.customer == Query.identity()
          }
        END
      }
    }
  ],
  membership: [
    {
      resource: "Manager"
    },
    {
      resource: "User",
      predicate: "(user) => user.accessLevel == \"manager\""
    }
  ]
}

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!