Pass through an access token
A server route needs to forward the user's bearer credential to another service.
Kinde · Module
getAccessTokenRaw asynchronously retrieves the raw access token through the Next.js App Router server-session API. Use it when server-side code needs the token value itself.
In the Next.js App Router SDK, obtain the server-session helpers, call getAccessTokenRaw asynchronously, and use the resulting access-token value in server-side code. The documentation presents it as a direct token-reading method rather than a decoded-token accessor.
const { getAccessTokenRaw } = getKindeServerSession();
const accessToken = await getAccessTokenRaw();A Promise resolving to the raw access token.
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
export async function GET() {
const { getAccessTokenRaw } = getKindeServerSession();
const accessToken = await getAccessTokenRaw();
return Response.json({ accessToken });
}Reads the raw access token in a Next.js server route and returns it as JSON.
A server route needs to forward the user's bearer credential to another service.
Server-side diagnostics need to inspect whether a token was returned.
Application code needs the token string rather than decoded claims.
Call getKindeServerSession() to obtain the session helpers, then await getAccessTokenRaw(). The documented Next.js example logs the resulting access token.
Follow-up: How would you get decoded token data instead? Use the SDK's separate getAccessToken method, which the page distinguishes from getAccessTokenRaw.
The call is asynchronous, so server-side code should await getAccessTokenRaw() before using the returned token. The page demonstrates this inside a server-side Next.js example.
Follow-up: What kind of code should contain this call? Keep it in server-side application code, where getKindeServerSession from the server entry point is available.
Import getKindeServerSession from @kinde-oss/kinde-auth-nextjs/server, destructure getAccessTokenRaw from the returned session helpers, and invoke it. This is the documented setup for the Next.js App Router SDK.
Follow-up: How would the browser API differ? The same page documents a browser client API separately, so use the browser-client hook there rather than the server import.
getAccessTokengetKindeServerSessionaccessTokenRawuseKindeBrowserClient