Skip to main content
getAccessToken is a client-side function that retrieves an access token for the currently authenticated user. It fetches tokens from the /auth/access-token endpoint, which handles token refresh automatically if needed.
This is the client-side version. For server-side token retrieval, see getAccessToken (Server).

Usage

Basic Usage

Multi-API Applications

When calling multiple APIs with different audiences, specify the audience parameter:

Request Additional Scopes

Get Full Token Response

Signature

Parameters

AccessTokenOptions
Options for fetching the access token.

Return Value

When includeFullResponse is false (default)

Returns a Promise<string> containing the access token.

When includeFullResponse is true

Returns a Promise<AccessTokenResponse> with the following properties:
string
required
The access token string.
string
The scopes granted for this token.
number
Unix timestamp (in seconds) when the token expires.
number
Number of seconds until the token expires.
string
The token type (e.g., "Bearer", "DPoP").

Error Handling

Configuration

By default, the function fetches from /auth/access-token. You can customize this endpoint using the NEXT_PUBLIC_ACCESS_TOKEN_ROUTE environment variable:

Multi-Resource Refresh Tokens (MRRT)

When using audience or scope parameters, you must configure Multi-Resource Refresh Tokens in your Auth0 Application:
  1. Go to your Auth0 Application settings
  2. Navigate to Advanced Settings > Grant Types
  3. Enable Refresh Token
  4. Configure Refresh Token Policies with the audiences and scopes your application needs
See the Auth0 MRRT documentation for more details.

Notes

  • This function only works on the client side (browser)
  • The user must be authenticated before calling this function
  • Tokens are automatically refreshed if expired
  • For server-side token retrieval, use the server-side getAccessToken method from Auth0Client