# Post Login Action - Claims Missing in JWT

**URL:** <https://community.auth0.com/t/post-login-action-claims-missing-in-jwt/170307>\
**Category:** Get Help\
**Tags:** auth0-authorization, extensions\
**Created:** [January 25, 2025, 10:09pm UTC](https://community.auth0.com/t/post-login-action-claims-missing-in-jwt/170307 "2025-01-25T22:09:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![3dyuval](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/3dyuval/32/71525_2.png) [@3dyuval](https://community.auth0.com/u/3dyuval)\
**Post date:** [January 25, 2025, 10:09pm UTC](https://community.auth0.com/t/post-login-action-claims-missing-in-jwt/170307/1 "2025-01-25T22:09:59Z")

</div>

Hi everyone,

I’ve searched extensively on this topic and found it brought up multiple times, but haven’t come across a clear solution.

I’m trying to set custom claims in the JWT idToken and accessToken using a Post Login Action in Auth0. Here’s what I’ve done so far:

1. **Created a Post Login Action** with the following code:

```auto
exports.onExecutePostLogin = async (event, api) => { 
    const namespace = 'namespace-preffix';
 
    if (event.authorization) { 
        console.log(event.authorization.roles); // Successfully logs the roles
        api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles); 
        api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles); 
    } 
};

```

1. **Bound the Action** to the appropriate Post Login flow in the **Triggers** section.

Despite this setup:

- The roles are successfully logged in the Action Logs (`event.authorization.roles` logs correctly).
- However, the custom claims never show up in the JWT idToken or accessToken.

I expect the custom claim (`namespace/roles`) to appear in the token payload, but it’s consistently missing.

Has anyone encountered this issue or know of any steps I might be missing? Any guidance would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![sumansaurav](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sumansaurav/32/70627_2.png) [@sumansaurav](https://community.auth0.com/u/sumansaurav)\
**Post date:** [January 27, 2025, 11:06pm UTC](https://community.auth0.com/t/post-login-action-claims-missing-in-jwt/170307/3 "2025-01-27T23:06:14Z")

</div>

Hi @3dyuval ,

Would you mind sharing:

- The format of your roles NOT real data data when it’s logged?

Try explicitly converting it to an array if needed:

```auto
api.idToken.setCustomClaim(`${namespace}/roles`, Array.from(event.authorization.roles));

```

You can also check the guidelines to use namespace identifier here:

> **[Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines)**
>
> Learn how to create collision-resistant names for custom claims.

You also need to verify your client application is configured to receive these custom claims:

- Check if the client’s “Token Endpoint Authentication Method” is properly set
- Verify that the necessary scopes are included in your authentication request

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [January 28, 2025, 12:57pm UTC](https://community.auth0.com/t/post-login-action-claims-missing-in-jwt/170307/4 "2025-01-28T12:57:36Z")

</div>

Hi @3dyuval

Welcome to the Auth0 Community!

Thank you for posting your question. The Action code for adding the claims looks good, and I successfully tested a similar code a few minutes ago. Could you check if your application is passing the audience in the request? I’m guessing that you could be getting an opaque token, not a valid JWT → [Why Access Token Is Not a JWT (Opaque Token)](https://community.auth0.com/t/why-access-token-is-not-a-jwt-opaque-token/31028)

Thanks  
Dawid

---

<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:** [February 11, 2025, 12:58pm UTC](https://community.auth0.com/t/post-login-action-claims-missing-in-jwt/170307/5 "2025-02-11T12:58:30Z")

</div>

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