# Custom Claims not showing up in NextJS Session

**URL:** <https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [August 14, 2025, 4:55pm UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622 "2025-08-14T16:55:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonminor](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jasonminor/32/71057_2.png) [@jasonminor](https://community.auth0.com/u/jasonminor)\
**Post date:** [August 14, 2025, 4:55pm UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622/1 "2025-08-14T16:55:55Z")

</div>

I’m trying to get custom claims to show up in my application and I’m having issue. I’ve read through several other topics with people have the same issue, but nothing I’ve tried so far has worked.

Below I’ve replaced my app URL with `app.mysite.com`

Here is my post-login action:

```auto
exports.onExecutePostLogin = async (event, api) => {
  api.idToken.setCustomClaim('https://app.mysite.com/test', 'hello-test');
  api.accessToken.setCustomClaim('https://app.mysite.com/access-test', 'hello-access-token-test');

  if (event.authorization) {
    api.idToken.setCustomClaim('https://app.mysite.com/roles', event.authorization.roles);
  }
};

```

and here is my `auth0.ts` library setup:

```auto
import { Auth0Client } from "@auth0/nextjs-auth0/server";

// Initialize the Auth0 client 
export const auth0 = new Auth0Client({
  // Options are loaded from environment variables by default
  // Ensure necessary environment variables are properly set
  // domain: process.env.AUTH0_DOMAIN,
  // clientId: process.env.AUTH0_CLIENT_ID,
  // clientSecret: process.env.AUTH0_CLIENT_SECRET,
  // appBaseUrl: process.env.APP_BASE_URL,
  // secret: process.env.AUTH0_SECRET,

  authorizationParameters: {
    // In v4, the AUTH0_SCOPE and AUTH0_AUDIENCE environment variables for API authorized applications are no longer automatically picked up by the SDK.
    // Instead, we need to provide the values explicitly.
    scope: process.env.AUTH0_SCOPE,
    audience: process.env.AUTH0_AUDIENCE,
  }
});

```

and environment variables with the sensitive information redacted

```auto
AUTH0_SECRET='SECRET'
APP_BASE_URL='http://localhost:3000'
AUTH0_DOMAIN='https://mysite.us.auth0.com'
AUTH0_CLIENT_ID='CLIENT_ID'
AUTH0_CLIENT_SECRET='CLIENT_SECRET'
AUTH0_AUDIENCE='https://mysite.us.auth0.com/api/v2/'
AUTH0_SCOPE='openid profile'

```

Here is my NextJS Auth0 setup where I’m trying to read it

```auto
export async function middleware(request: NextRequest) {
    const auth0Response: NextResponse = await auth0.middleware(request);

    const session = await auth0.getSession(request);
    console.log("Session:", session);
    // Session doesn't include the above claims

    ...

```

For good measure, I also check in a server side component to see if it showed up there, but it didn’t

```auto
import React from 'react';

import { auth0 } from '../lib/auth0';

export default async function Page() {
    const session = await auth0.getSession();
    console.log("Session in LawFirmsListPage:", session);
    ....

```

I’ve confirmed:

- The action is deployed
- The action is in the `post-login` trigger and it is saved
- I’ve tried logging out and logging back in again before checking the claims
- I’ve also tried going incognito and had the same issue

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [August 18, 2025, 6:20pm UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622/3 "2025-08-18T18:20:35Z")

</div>

Hi @jasonminor

Welcome to the Auth0 Community!

I am sorry about the delayed response to your inquiry!

In the meantime, could you try the following code and let me know if it fixes the issue?

```auto
import { Auth0Client } from "@auth0/nextjs-auth0/server";

export const auth0 = new Auth0Client({
  async beforeSessionSaved(session, idToken) {
    return session;
  }
});

```

As far as I know, you have to configure the client to save the additional claims to the session, otherwise they will be filtered out since they are not part of the default claims.

I will come back as soon as possible with further details regarding the matter! If you have any other questions or further updates, let me know!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![jasonminor](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jasonminor/32/71057_2.png) [@jasonminor](https://community.auth0.com/u/jasonminor)\
**Post date:** [August 18, 2025, 11:37pm UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622/4 "2025-08-18T23:37:07Z")

</div>

Hi @nik.baleca,

I added that code and it worked great! I can see all my custom claims now. Thanks!

For my own reference, how does that code you’ve pasted save additional claims to the session?

---

<div class="post-metadata">

**Author:** ![Rama](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Rama](https://community.auth0.com/u/Rama)\
**Post date:** [August 19, 2025, 12:02am UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622/5 "2025-08-19T00:02:33Z")

</div>

Hi @jasonminor, are you able to see the claims after a token refresh?  
I’m experiencing a similar issue: I can see the custom claims after login, but when I call `getAccessToken()` to refresh the token once it expires, the new access token doesn’t contain any claims.

---

<div class="post-metadata">

**Author:** ![jasonminor](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jasonminor/32/71057_2.png) [@jasonminor](https://community.auth0.com/u/jasonminor)\
**Post date:** [August 19, 2025, 3:38pm UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622/6 "2025-08-19T15:38:16Z")

</div>

Hey @Rama, my situation might be unique because I’m reading these custom claims off the session variable, not from the token. I haven’t looked into reading custom claims from the token yet, but maybe there is a similar function like `beforeTokenSaved` or something similar that might do this?

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [August 19, 2025, 4:36pm UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622/7 "2025-08-19T16:36:50Z")

</div>

Hi again!

To answer your question @jasonminor, this information can be found in our [documentation](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#beforesessionsaved) regarding NextJS’s `beforeSessionSaved` hook. To save you some time, basically the hook is run right before the session is persisted. It helps modify the session claims before persisting them.

The `session.user` object passed to the `beforeSessionSaved` hook will contain every claim in the ID Token, including custom claims. You can use the `filterDefaultIdTokenClaims` utility to filter out the standard claims and only keep the custom claims you want to persist. The code provided above allows you to use the entire `session.user` object if you would like to include every claim in the ID Token. Alternatively, have you tried using the `useUser()` hook in order to see if the custom claims set by the actions are visible?

Otherwise @Rama, I will be addressing your issue in the post you have created regarding the matter as soon as possible!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 10, 2025, 3:35pm UTC](https://community.auth0.com/t/custom-claims-not-showing-up-in-nextjs-session/190622/8 "2025-09-10T15:35:47Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
