CurrentIdentity

Not available in this language yet.
Not available in this language yet.
CurrentIdentity()
CurrentIdentity()
current_identity()
CurrentIdentity()

Description

The CurrentIdentity function returns the Reference of the document associated with the authentication token used for the request. If a document does not exist, an error is returned.

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 associated with the current client authentication token.

Examples

The following query is run in the context of a logged-in Fauna user:

Not available in this language, yet.
Not available in this language, yet.
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', err))
Ref(Collection("users"), "1")
result = client.query(
  q.current_identity()
)
print(result)
Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections)))
try {
  println(Await.result(
    client.query(
      CurrentIdentity()
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections")))

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

Not available in this language, yet.
Not available in this language, yet.
System.out.println(
    client.query(
        CurrentIdentity()
    ).get());
"l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients"
client.query(
  q.CurrentIdentity()
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients
Not available in this language, yet.
try {
  println(Await.result(
    client.query(
      CurrentIdentity()
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
"l6vJS8QvHC2LmiGRaOTiE16givuufR22@clients"

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!