# Customize your session token

Session tokens are JWTs generated by Clerk on behalf of your instance, and convey an authenticated user session to your backend.

By default, session tokens contain claims that are required for Clerk to function. You can learn more about these "default claims" in the [session tokens](https://clerk.com/docs/guides/sessions/session-tokens.md) documentation.

This guide will show you how to customize a session token to include additional claims that you may need in your application.

> Clerk stores the session token in a cookie, and most browsers cap cookie size at [**4KB**](https://datatracker.ietf.org/doc/html/rfc2109#section-6.3). After accounting for the size of Clerk's default claims, the cookie can support **up to 1.2KB** of custom claims. Exceeding this limit will cause the cookie to not be set, which will break your app as Clerk depends on cookies to work properly. [Learn more](https://clerk.com/docs/guides/sessions/session-tokens.md#size-limitations).

1. ## Add custom claims to your session token

   1. In the Clerk Dashboard, navigate to the [**Sessions**](https://dashboard.clerk.com/~/sessions) page.
   2. Under **Customize session token**, in the **Claims** editor, you can add any claim to your session token that you need and select **Save**.

   The following example adds the `fullName` and `primaryEmail` claims to the session token.

   ![Clerk Dashboard showing the custom claim modal](https://clerk.com/docs/raw/_public/images/custom-session-token/example.png)
2. ## Use the custom claims in your application

   The [`Auth`](https://clerk.com/docs/reference/backend/types/auth-object.md) object includes a `sessionClaims` property that contains the custom claims you added to your session token. **Accessing the `Auth` object differs depending on the SDK you're using. See the [reference doc](https://clerk.com/docs/reference/backend/types/auth-object.md) for more information.**

   The following example demonstrates how to access the `fullName` and `primaryEmail` claims that were added to the session token in the last step.

   **Next.js**

   For Next.js, the `Auth` object is accessed using the `auth()` helper in App Router apps and the `getAuth()` function in Pages Router apps. Learn more about [using Next.js helpers](https://clerk.com/docs/nextjs/guides/users/reading.md#server-side).

   **App Router**

   filename: app/api/example/route.tsx

   ```tsx
   import { auth } from '@clerk/nextjs/server'
   import { NextResponse } from 'next/server'

   export async function GET() {
     // Use `auth()` to access the user's session claims
     const { isAuthenticated, sessionClaims } = await auth()

     if (!isAuthenticated) {
       return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
     }

     const fullName = sessionClaims.fullName

     const primaryEmail = sessionClaims.primaryEmail

     return NextResponse.json({ fullName, primaryEmail })
   }
   ```

   **Pages Router**

   filename: pages/api/example.ts

   ```tsx
   import { getAuth } from '@clerk/nextjs/server'
   import type { NextApiRequest, NextApiResponse } from 'next'

   export default async function handler(req: NextApiRequest, res: NextApiResponse) {
     // Use `getAuth()` to access the user's session claims
     const { isAuthenticated, sessionClaims } = getAuth(req)

     if (!isAuthenticated) {
       return res.status(401).json({ error: 'Unauthorized' })
     }

     const fullName = sessionClaims.fullName

     const primaryEmail = sessionClaims.primaryEmail

     return res.status(200).json({ fullName, primaryEmail })
   }
   ```
3. ## Add global TypeScript type for custom session claims

   To get auto-complete and prevent TypeScript errors when working with custom session claims, you can define a global type.

   1. In your application's root folder, add a `types` directory.
   2. Inside of the `types` directory, add a `globals.d.ts` file.
   3. Create the `CustomJwtSessionClaims` interface and declare it globally.
   4. Add the custom claims to the `CustomJwtSessionClaims` interface.

   The following example demonstrates how to add the `fullName` and `primaryEmail` claims to the `CustomJwtSessionClaims` interface.

   filename: types/globals.d.ts

   ```tsx
   export {}

   declare global {
     interface CustomJwtSessionClaims {
       fullName?: string
       primaryEmail?: string
     }
   }
   ```

---

## Sitemap

[Overview of all docs pages](https://clerk.com/docs/llms.txt)
