credential.exists()
Learn: Credentials |
---|
Test if a credential exists.
Description
Tests if a credential, represented
as an Credential
document,
exists.
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.
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:
Credential.byId("12345").exists() // true
Credential.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