AccessProvider.firstWhere()

Learn: Access providers

Gets the first matching AccessProvider collection document.

Signature

Collection.firstWhere(predicate: () => Boolean)): AccessProvider | NullAccessProvider

Collection.firstWhere(predicate: (val: AccessProvider) => Boolean)): AccessProvider | NullAccessProvider

Description

Each access provider document in a Fauna database is in the AccessProvider collection. This method returns the first accessible provider that matches the predicate function.

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

predicate

Function

Anonymous function that returns the first accessible provider that matches the predicate function.

predicate parameters:

Parameter Type Required Description

val

AccessProvider

A provider to compare. If omitted, use dot notation to access provider properties.

Return value

One of:

Type Description

AccessProvider

First accessible document matching the predicate function.

Null

When no provides match the predicate function or all matching providers are inaccessible.

Examples

AccessProvider.firstWhere(.issuer == "https://example.com/")
{
  name: "someIssuer",
  coll: AccessProvider,
  ts: Time("2099-06-25T14:57:23.125Z"),
  jwks_uri: "https://example.com/.well-known/jwks.json",
  roles: [
    "customer",
    {
      role: "manager",
      predicate: "(jwt) => jwt!.scope.includes(\"manager\")"
    }
  ],
  audience: "https://db.fauna.com/db/ysjowue14yyr1",
  issuer: "https://example.com/"
}

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!