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.

Key.create()

Learn: Keys

Create a key.

Signature

Key.create(data: { role: String, database: String | Null, ttl: Time | Null, data: { *: Any } | Null }) => Key

Description

Creates a key with the provided document fields. Fauna stores keys as documents in the Key system collection.

A key is a type of authentication secret used for anonymous access to a Fauna database. Unlike tokens, keys are not associated with an identity.

Parameters

Parameter Type Required Description

data

Object

true

Document fields for the new Key document.

For supported document fields, see Key collection.

Return value

Type Description

Key

The new Key document. Includes the key’s secret, which you can use to authenticate with Fauna.

A key’s secret is shown once — when you create the key. You can’t recover or regenerate a lost key secret. Instead, delete the key and create a new one.

Examples

Create a key with a user-defined role and which expires tomorrow:

Key.create({role: "admin", ttl: Time.now().add(1, "day")})
{
  id: "412655134325080576",
  coll: Key,
  ts: Time("2099-07-28T02:23:51.300Z"),
  ttl: Time("2099-07-29T02:23:51.189192Z"),
  secret: "fn...",
  role: "admin"
}

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!