token.exists()

Learn: Tokens

Test if a token exists.

Signature

exists() => true

Description

Tests if a token, represented as an Token document, exists.

A token is a type of authentication secret used to provide identity-based access to a Fauna database. Fauna stores tokens as documents in the Token system collection.

exists() vs. null comparisons

You can use either exists() or a null comparison (== null or != null) to check the existence or validity of a value. For example:

Token.byId("12345").exists()  // true
Token.byId("12345") != null   // true

Key differences:

  • exists() returns an error if called on an unsupported value.

  • Null comparisons do not throw errors and work safely on any value.

For example:

// Declare an object. Objects don't support
// an `exists()` method.
let object = { a: "Foo", b: "Bar" }

object.exists()  // Returns `invalid_query` error

object != null   // Returns true

Parameters

None

Return value

Type Description

Boolean

If true, the Token document exists. If false, the Token document doesn’t exist.

Examples

Token.byId("401671202234433613").exists()
true
\