# Custom Claim Does Not Show Up in Access Token

**URL:** <https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069>\
**Category:** Get Help\
**Tags:** login-prompt-new-experience, login-experience\
**Created:** [June 10, 2024, 5:40pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069 "2024-06-10T17:40:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark29](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mark29/32/48577_2.png) [@mark29](https://community.auth0.com/u/mark29)\
**Post date:** [June 10, 2024, 5:40pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069/1 "2024-06-10T17:40:01Z")

</div>

I’m having issues setting a custom claim on the `accessToken` in the Flow \> Login script. I’m using the auth0 SPA JS SDK [GitHub - auth0/auth0-spa-js: Auth0 authentication for Single Page Applications (SPA) with PKCE](https://github.com/auth0/auth0-spa-js)

Here is how I’m creating the client:

```js
auth0.createAuth0Client({
        domain: ...,
        clientId: ...,
        authorizationParams: {
            redirect_uri: "http://localhost:3000"
        },
        useRefreshTokens: true,
        cacheLocation: 'localstorage'
    })

```

Here is the Flow \> Login script to add a custom claim to the `accessToken`

```js
exports.onExecutePostLogin = async (event, api) => {
  if (event.authorization) {
    api.accessToken.setCustomClaim('test', "hello");
  }
}

```

but I do not see the custom claim come through in the `accessToken` when calling `const t = await auth0Client.getTokenSilently();` This returns a JWT with no data payload `...mwzciJ9..H7dP7YQ1...`

However it works when setting the custom claim on the `idToken` when using

```jsx
exports.onExecutePostLogin = async (event, api) => {
  if (event.authorization) {
    api.idToken.setCustomClaim('test', "hello");
  }
}

```

Any ideas why the `accessToken` does not include the custom claim from the Flow \> Login script?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 10, 2024, 5:52pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069/3 "2024-06-10T17:52:05Z")

</div>

Hello @mark29 welcome to the community!

> [@mark29](#):
>
> but I do not see the custom claim come through in the `accessToken` when calling `const t = await auth0Client.getTokenSilently();` This returns a JWT with no data payload `...mwzciJ9..H7dP7YQ1...`

This is due to the lack of an `audience` param being passed in the authorize request - You can add this param in [authorizationOptions](https://auth0.github.io/auth0-spa-js/interfaces/AuthorizationParams.html#audience). Without it, you’ll get an [opaque](https://auth0.com/docs/secure/tokens/access-tokens#opaque-access-tokens) token returned as you’ve seen.

[https://community.auth0.com/t/what-is-the-audience/71414](https://community.auth0.com/t/what-is-the-audience/71414)

---

<div class="post-metadata">

**Author:** ![mark29](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mark29/32/48577_2.png) [@mark29](https://community.auth0.com/u/mark29)\
**Post date:** [June 10, 2024, 6:18pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069/4 "2024-06-10T18:18:06Z")

</div>

I’ve added the audience to the config but getting this error now

```auto
Auth0Client.ts:503 Uncaught (in promise) Error: Service not found: https://nativeframe-prod-usc1b.nativeframe.com
    at ce.handleRedirectCallback (Auth0Client.ts:503:13)
    at auth.js:68:31

```

Options for reference

```auto
auth0.createAuth0Client({
        domain: ...,
        clientId: ...,
        authorizationParams: {
            redirect_uri: "http://localhost:3000",
            audience: "https://nativeframe-prod-usc1b.nativeframe.com"
        },
        useRefreshTokens: true,
        cacheLocation: 'localstorage'
    })

```

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 10, 2024, 6:23pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069/5 "2024-06-10T18:23:38Z")

</div>

> [@mark29](#):
>
> `https://nativeframe-prod-usc1b.nativeframe.com`

Do you have `https://nativeframe-prod-usc1b.nativeframe.com` as a [registered API](https://auth0.com/docs/get-started/auth0-overview/set-up-apis) in your dashboard?

---

<div class="post-metadata">

**Author:** ![mark29](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mark29/32/48577_2.png) [@mark29](https://community.auth0.com/u/mark29)\
**Post date:** [June 10, 2024, 6:35pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069/6 "2024-06-10T18:35:33Z")

</div>

Ah no, that’s what it was. Thank you!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 10, 2024, 6:37pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069/7 "2024-06-10T18:37:35Z")

</div>

Awesome, thanks for confirming!

---

<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:** [June 24, 2024, 6:37pm UTC](https://community.auth0.com/t/custom-claim-does-not-show-up-in-access-token/136069/8 "2024-06-24T18:37:55Z")

</div>

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