Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Kinde · Function

getAccessToken

getAccessToken() asynchronously reads Kinde’s cached raw access-token JWT for use in API requests. It does not refresh the token and can return undefined or an expired token.

How it works

Call the method to read the access-token JWT currently held in session storage. It returns the cached value without refreshing it, so callers should handle an absent token and understand that the returned token may already be expired.

Syntax

const token = await getAccessToken();

Returns

Promise<string | undefined> — the cached raw access-token JWT, or undefined if no token is stored.

Key points

  • The result is the raw access-token JWT, not a decoded token or an error wrapper.
  • Use this hook method when a frontend needs to obtain the credential for an API request.
  • The asynchronous result is either the cached JWT or undefined when storage has no token.
  • A stored token is returned as-is, including an expired JWT; this method does not contact the token endpoint.
  • Use getAccessToken() rather than the deprecated getToken() method.

Common mistakes

  • The method only reads the cached JWT, so it can return an expired token. Use refreshToken() when an explicit refresh is required.
  • Do not use exception handling or an error-object branch to detect a missing token; the result is undefined instead.

Example: Call an API with the cached access token

import { useKindeAuth } from "@kinde-oss/kinde-auth-react";

export async function callApi() {
  const { getAccessToken } = useKindeAuth();
  const token = await getAccessToken();
  if (!token) return;

  const response = await fetch("https://api.example.com/data", {
    headers: { Authorization: `Bearer ${token}` },
  });
  return response.json();
}

Reads the cached token and sends it to an API as a bearer token.

When to use it

Attach a bearer token to an API request

A signed-in React frontend needs to call a protected backend API.

Check authentication state before a request

An application needs to determine whether a cached access token exists.

Read a token after explicit refresh

A caller needs a newly refreshed credential.

Interview questions

QWhat does getAccessToken return?

getAccessToken() returns a Promise<string | undefined>. It reads the raw cached access-token JWT from session storage and returns undefined when no token is stored.

Follow-up: How would you obtain a fresh token? Call refreshToken() first, then call getAccessToken() to read the refreshed value.

QDoes it refresh an expired token?

No. The method only reads the cached token and does not call Kinde’s token endpoint. The returned JWT may therefore be expired.

Follow-up: Why might a subsequent call return a newer token? The SDK can refresh silently in the background, after which getAccessToken() reads the updated cached value.

QHow is the returned token used?

Use the value as a bearer credential in the Authorization header when calling an API. Check for undefined before constructing the request, because signed-out users may have no stored token.

Follow-up: What should the API do with the bearer token? Validate the JWT server-side before authorizing the request.

  • useKindeAuth
  • refreshToken
  • getToken
  • Authorization bearer token

Source: React SDK. Checked 2026-10-15.