Credential.firstWhere()

Learn: Credentials

Get the first credential that matches a provided predicate.

Signature

Credential.firstWhere(pred: (Credential => Boolean)) => Credential | Null

Description

Gets the first credential, represented as a Credential document, that matches a provided predicate function.

A credential associates a password with an identity document. You can use credentials and the credential.login() method to create tokens as part of an end-user authentication system.

Parameters

Parameter Type Required Description

pred

Predicate function

Yes

Anonymous predicate function that:

The method returns the first Credential document for which the predicate returns true.

Return value

One of:

Type Description

Credential

First Credential document that matches the predicate.

Null

No Credential document matches the predicate.

Examples

Credential.firstWhere(.document == Customer.byId("111"))
{
  id: "371153420791316514",
  coll: Credential,
  ts: Time("2099-07-24T17:05:34.890Z"),
  document: Customer("111")
}
\