Create a token

Problem

You need to create a token in the current database.

Solution

Use the Login function:

Copied!
(
  (("characters"), "181388642114077184"),
  { password: "abracadabra" },
)
{
  ref: ((), "309833029179671040"),
  ts: 1631738652300000,
  instance: (("characters"), "181388642114077184"),
  secret: 'fnEETL9_m_ACAARMv36xQAYA0e8RzC8kR9TQDLEM5tEpq79-w_M'
}
Query metrics:
  •    bytesIn:  118

  •   bytesOut:  313

  • computeOps:    1

  •    readOps:    1

  •   writeOps:    1

  •  readBytes:  214

  • writeBytes:  414

  •  queryTime: 28ms

  •    retries:    0

You can also create one directly, if the identity document does not have any credentials defined:

Copied!
(
  (),
  {
    instance: (('characters'), '181388642114077184')
  }
)
{
  ref: ((), "309833028300964352"),
  ts: 1631738651480000,
  instance: (("characters"), "181388642114077184"),
  secret: 'fnEETL9_Z5ACAARMv36xQAYAsGq8dFWhaBsypurs5u8qAN6Zfm8'
}
Query metrics:
  •    bytesIn:  121

  •   bytesOut:  313

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:    0

  • writeBytes:  414

  •  queryTime: 41ms

  •    retries:    0

The token’s secret is only ever shown once, in the response from the Login function. If you lose the secret, delete the token 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!