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

Kinde · Module

getAccessTokenRaw

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.

How it works

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.

Syntax

const { getAccessTokenRaw } = getKindeServerSession();
const accessToken = await getAccessTokenRaw();

Returns

A Promise resolving to the raw access token.

Key points

  • Its purpose is to retrieve the access token itself rather than a decoded representation.
  • Create the server session object, then destructure the raw-token method from it.
  • Invoke the method asynchronously and store the resolved token value.
  • The documentation demonstrates using the resolved value directly after retrieval.

Common mistakes

  • This returns the raw access token string, not a decoded token object.

Example: Read 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.

When to use it

Pass through an access token

A server route needs to forward the user's bearer credential to another service.

Check token availability

Server-side diagnostics need to inspect whether a token was returned.

Use the raw token

Application code needs the token string rather than decoded claims.

Interview questions

QHow do you retrieve a raw access token in the Next.js App Router SDK?

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.

QWhy does the example use await with 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.

QWhat setup is required before calling getAccessTokenRaw()?

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.

  • getAccessToken
  • getKindeServerSession
  • accessTokenRaw
  • useKindeBrowserClient

Source: Next.js App Router SDK - Kinde docs. Checked 2026-10-15.