Create a key

A Fauna key, or access token, gives a client application access to a Fauna database.

Each key has an assigned role. Keys support both built-in and user-defined roles.

This tutorial shows how you can create a key using:

  • The Fauna Dashboard

  • An FQL query using the Key.create() method

Create a key using the Dashboard

To create a key in the Dashboard:

  1. Go to the Fauna Dashboard and sign in.

  2. In the left navigation, click Explorer.

  3. Expand your region group, select your database, and click the Keys tab.

  4. Click Create Key.

  5. Choose a Role and enter an optional Key Name.

  6. Click Save.

  7. Copy the Secret Key.

Create a key using Key.create()

To create a key using Key.create():

Key.create({
  role: "server",
  // Optional key name
  data: {
    name: "my-server-key"
  }
})

To call Key.create(), you must have the create privilege for the built-in Key collection. The built-in admin role has this privilege.

Get all keys

Use Key.all() to get all keys for a database:

Key.all()

Response:

{
  data: [
    {
      id: "394168889163907136",
      coll: Key,
      ts: Time("2099-04-03T18:06:35.936Z"),
      data: {
        name: "my-server-key"
      },
      role: "server"
    },
    ...
  ]
}

To get results from Key.all(), you must have the read privilege for the Key collection.

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!