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()
Create an key.
Description
The Key.create()
method creates a Key with the provided data.
A key can’t be create with greater privileges than the key used when calling this method.
If a database isn’t provided, the requested access level is associated with the current database.
The method returns a document that incudes a secret field, which is equivalent to a password and must be copied and stored.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
data |
Object describing the key. |
data fields
Name | Type | Required | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
role |
Yes |
Key privilege. A role can be a user-defined role or one of the following built-in roles:
|
|||||||||||
database |
Name of an existing database. If omitted, the key grants access to the current database. |
||||||||||||
priority |
A relative weight from |
||||||||||||
data |
User-defined metadata to store supplemental key information. |
||||||||||||
ttl |
Time-to-live timestamp indicating the key lifespan. |
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!