CurrentIdentity
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
CurrentIdentity()
current_identity()
CurrentIdentity()
CurrentIdentity()
CurrentIdentity()
CurrentIdentity()
Description
The CurrentIdentity
function returns the Reference of the identity document
involved in the current query, if there is one. You can use the
Reference to fetch the identity document and inspect its contents.
Authorization for every Fauna query involves a secret, which was created by a key, token, or is embedded in a JSON Web Token (JWT).
The secrets for keys provide anonymous,
role-based access to a Fauna database, so no identity document is
available. If you call CurrentIdentity
when using a key’s secret, an error
occurs.
When authentication is performed by an
identity provider, CurrentIdentity
returns the contents of the associated JWT’s sub
field.
Returns
A Reference to the identity document authorized to run the current query, or an error when using anonymous authorization.
Examples
The following query is run in the context of a logged-in Fauna user:
Ref(Collection("users"), "1")
Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections)))
{1 0xc000109710 0xc000109710 <nil>}
RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections")))
ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections")))
Ref(Collection("users"), "1")
The following query is run in the context of an externally-authenticated user:
l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients
l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients
l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients
StringV(l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients)
"l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients"
'8cYrAhHUTtqr9eSliRmdrGryJhYbcPQA@clients'