The Auth object contains important information like the current user's session ID, user ID, and organization ID. It also contains methods to check for permissions and retrieve the current user's session token.
Note
The structure of the Auth object varies depending on the type of request.
For machine-authenticated requests (e.g. using an API key or OAuth token), the object reflects machine-level authentication data instead of user session details.
If you're working with machine-authenticated requests, refer to the Machine properties section for a detailed breakdown.
The Auth object is available on the request object in server contexts. Some frameworks provide a helper that returns the Auth object. See the following table for more information.
The has() helper can be used to do two types of checks:
Authorization: Check if the user has been granted a specific type of access control (role, permission, feature, or plan) and returns a boolean value. For examples, see the guide on verifying if a user is authorized.
Reverification: Check if the user has verified their credentials within a certain time frame and returns a boolean value. For examples, see the guide on reverification.
Providing a template will perform a network request and will count towards rate limits.
constgetToken:ServerGetTokentypeServerGetToken= (options?:ServerGetTokenOptions) =>Promise<string|null>typeServerGetTokenOptions= { template?:string// The name of the custom JWT template to retrieve.}
The following is an example of the Auth object without an active organization. Notice that there is no o claim. Read more about token claims in the guide on session tokens.
Version 2
Version 1
Important
This example is for version 2 of Clerk's session token. To see an example of version 1, select the respective tab above.
The following is an example of the Auth object with an active organization. Notice the addition of the o claim. Read more about token claims in the guide on session tokens.
Version 2
Version 1
Important
This example is for version 2 of Clerk's session token. To see an example of version 1, select the respective tab above.
The following is an example of the Auth object with a valid factor age. Notice the addition of the fva claim with a value of [0, 0], indicating that the first and second factors have been verified within the past minute. Read more about token claims in the guide on session tokens.
Version 2
Version 1
Important
This example is for version 2 of Clerk's session token. To see an example of version 1, select the respective tab above.
The following is an example of the Auth object of a user without an MFA method registered. Notice the addition of the fva claim, but the value is [0, -1]. 0 indicates that the first factor has been verified within the past minute, and -1 indicates that there is no second factor registered for the user. Read more about token claims in the guide on session tokens.
Version 2
Version 1
Important
This example is for version 2 of Clerk's session token. To see an example of version 1, select the respective tab above.
The following is an example of the Auth object of an authenticated machine request (i.e. a request authenticated using a machine token like an API key).
Notice the addition of a tokenType property with the value of 'api_key', which distinguishes the request as a machine request rather than a user session. The scopes array defines the permissions granted by the token.