token.exists()
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