# JWT payload is empty

**URL:** <https://community.auth0.com/t/jwt-payload-is-empty/81516>\
**Category:** Get Help\
**Tags:** bug\
**Created:** [April 10, 2022, 5:37pm UTC](https://community.auth0.com/t/jwt-payload-is-empty/81516 "2022-04-10T17:37:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krzysztof1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/krzysztof1/32/36235_2.png) [@krzysztof1](https://community.auth0.com/u/krzysztof1)\
**Post date:** [April 10, 2022, 5:37pm UTC](https://community.auth0.com/t/jwt-payload-is-empty/81516/1 "2022-04-10T17:37:37Z")

</div>

I’m trying to populate JWT payload with Hasura details using actions login flow

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://hasura.io/jwt/claims";
  api.accessToken.setCustomClaim(namespace,
    {
      'x-hasura-default-role': 'user',
      // do some custom logic to decide allowed roles
      'x-hasura-allowed-roles': ['user'],
      'x-hasura-user-id': event.user.user_id
    });
};

```

I was testing using `POST https://<domain>/oauth/token`  
id token and access token is returned however access token has empty payload  
to add more details whatabyte s throwing an error `Error in event handler: TypeError: Cannot convert undefined or null to object` - where I guess it’s about JWT empty payload

---

<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:** [April 12, 2022, 1:32am UTC](https://community.auth0.com/t/jwt-payload-is-empty/81516/3 "2022-04-12T01:32:07Z")

</div>

Hi there @krzysztof1!

> [@krzysztof1](#):
>
> id token and access token is returned however access token has empty payload

While I’m not familiar with Hasura, I’d be curious to know if the access token is actually empty or are you referring to the fact that the custom claims weren’t added?

Looking at our examples [here](https://auth0.com/docs/manage-users/access-control/sample-use-cases-actions-with-authorization#add-user-roles-to-tokens), I’m not sure the code you’ve shared will work (it didn’t for me in testing). Typically, each custom claim is added like this:

```auto
exports.onExecutePostLogin = async (event, api) => {
   const namespace = 'https://my-app.example.com';
   api.accessToken.setCustomClaim(`${namespace}/a`, claim_a);
   api.accessToken.setCustomClaim(`${namespace}/b`, claim_b);
   api.accessToken.setCustomClaim(`${namespace}/c`, claim_c);
}

```

Let us know!

---

<div class="post-metadata">

**Author:** ![krzysztof1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/krzysztof1/32/36235_2.png) [@krzysztof1](https://community.auth0.com/u/krzysztof1)\
**Post date:** [April 12, 2022, 4:56pm UTC](https://community.auth0.com/t/jwt-payload-is-empty/81516/4 "2022-04-12T16:56:39Z")

</div>

Hi @ty.frith,

the issue was that I haven’t set up audience for my JWT so I was receiving JWE.  
There was missing payload between JWT headers and signature (like double dots header…signature)

However I will try with setCustomClaim as I haven’t seen that.  
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:** [April 12, 2022, 8:49pm UTC](https://community.auth0.com/t/jwt-payload-is-empty/81516/5 "2022-04-12T20:49:41Z")

</div>

Awesome, thanks for the update - Always happy to help!

---

<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:** [April 27, 2022, 8:50pm UTC](https://community.auth0.com/t/jwt-payload-is-empty/81516/6 "2022-04-27T20:50:04Z")

</div>

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