CurrentIdentity

CurrentIdentity()
CurrentIdentity()
CurrentIdentity()
CurrentIdentity()
current_identity()
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.

Parameters

None.

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:

try
{
    Value result = await client.Query(
        CurrentIdentity()
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections")))
result, err := client.Query(
	f.CurrentIdentity())

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
{1 0xc000109710 0xc000109710 <nil>}
System.out.println(
    client.query(
        CurrentIdentity()
    ).get());
ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections")))
client.query(
  q.CurrentIdentity()
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
Ref(Collection("users"), "1")
result = client.query(
  q.current_identity()
)
print(result)
Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections)))
CurrentIdentity()
Ref(Collection("users"), "1")
Query metrics:
  •    bytesIn:   25

  •   bytesOut:  112

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    0

  •  readBytes:   96

  • writeBytes:    0

  •  queryTime: 30ms

  •    retries:    0

The following query is run in the context of an externally-authenticated user:

try
{
    Value result = await client.Query(
        CurrentIdentity()
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
StringV(l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients)
result, err := client.Query(
	f.CurrentIdentity())

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients
System.out.println(
    client.query(
        CurrentIdentity()
    ).get());
"l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients"
client.query(
  q.CurrentIdentity()
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients
result = client.query(
  q.current_identity()
)
print(result)
l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients
CurrentIdentity()
'8cYrAhHUTtqr9eSliRmdrGryJhYbcPQA@clients'
Query metrics:
  •    bytesIn:  25

  •   bytesOut:  55

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 4ms

  •    retries:   0

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!