Avoid repeated Backend API lookups
A backend repeatedly needs a small set of user attributes and can tolerate token refresh latency.
Clerk · Pipe
sessionClaims exposes claims from the current Clerk session token through the Auth object. Configure custom claims in Clerk's session-token editor, then read them with the authentication API for your SDK.
The Auth object exposes sessionClaims, containing claims from the current user's Clerk session token. Add custom claims in the Clerk Dashboard's session-token Claims editor, then read them through the authentication API appropriate to the SDK; token values can lag behind source data until the next refresh.
const { sessionClaims } = await auth()The current user's session claims, exposed as the sessionClaims property of the Auth object; the Auth reference types it as JwtPayload.
import { auth } from '@clerk/nextjs/server'
export default async function Page() {
const { userId, sessionClaims } = await auth()
if (!userId) return <p>Sign in required</p>
return <pre>{JSON.stringify(sessionClaims, null, 2)}</pre>
}This server component reads the authenticated user's session claims through Clerk's auth helper.
A backend repeatedly needs a small set of user attributes and can tolerate token refresh latency.
An application needs to make authorization or display decisions using compact role or profile data included in the session token.
A Go HTTP handler needs verified claims from Clerk middleware.
sessionClaims is a property of Clerk's Auth object and represents the current user's session claims. Custom claims are placed into the session token through the Clerk Dashboard's Claims editor and can then be read with the SDK-specific authentication API.
Follow-up: Why might a newly changed claim not appear immediately? The session token refreshes every 60 seconds, so use the Backend API or force a token refresh when immediate consistency is required.
Custom claims let the application receive selected user data with the session token instead of making a Backend API request for every read. This can reduce round trips, but the data may be briefly stale.
Follow-up: When should the Backend API be preferred? Use it when the change must be visible immediately or when the required data should not be carried in the token.
Clerk stores the session token in a browser cookie, and browsers commonly cap cookies at 4KB. After default claims are included, Clerk documents roughly 1.2KB as available for custom claims.
Follow-up: What design consequence follows? Include only compact, frequently needed fields and avoid placing large objects in the token.
Auth objectauth()useAuth()SessionClaimsFromContext()custom session tokensession tokens