Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

Token.create()

Learn: Tokens

Create a token without a credential or related password.

Signature

Token.create(data: { id: ID | Null, document: { *: Any } | Null, ttl: Time | Null, data: { *: Any } | Null }) => Token

Description

Creates a token that’s tied to an identity document without a credential or related password. This method is useful for creating tokens for servers, services, and other non-user identities.

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.

Create token with a credential

To create a token with a credential and related password, use credential.login() instead.

You typically use credential.login() to create and use tokens as part of a Fauna-based end-user authentication system.

Parameters

Parameter Type Required Description

data

Object

Document fields for the new Token document.

For supported document fields, see Token collection.

Return value

Type Description

Token

The new Token document.

Examples

Token.create({
  document: Customer.byId("111")
})
{
  id: "401671202234433613",
  coll: Token,
  ts: Time("2099-06-25T13:32:39.240Z"),
  document: Customer("111"),
  secret: "fn..."
}

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!