Create a key

Reading or writing key definitions requires an admin key.

Problem

You need to create a key in the current database.

Solution

Use the CreateKey function:

Copied!
adminClient.query(
  q.({
    database: q.('prydain'),
    role: 'server',
  })
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: ((), "309749247463391744"),
  ts: 1631658751850000,
  database: ("prydain"),
  role: 'server',
  secret: 'fnAETHNMqIACALQjS6v19qW8M2_gg-JNgn7ygC16',
  hashed_secret: '$2a$05$1SJ9KBqMn.YHXJT0P2VZs.6YrRY0Qx41KL/2A8tAGjJ3bAC4o.L1u'
}
Query metrics:
  •    bytesIn:    77

  •   bytesOut:   340

  • computeOps:     1

  •    readOps:     0

  •   writeOps:     1

  •  readBytes:   153

  • writeBytes:   487

  •  queryTime: 324ms

  •    retries:     0

The key’s secret is only ever shown once, in the response from the CreateKey function. If you lose the secret, delete the key and create a new one.

More information

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!