# Adding Hasura claims with actions

**URL:** <https://community.auth0.com/t/adding-hasura-claims-with-actions/71790>\
**Category:** Get Help\
**Tags:** custom-claims\
**Created:** [October 21, 2021, 3:03pm UTC](https://community.auth0.com/t/adding-hasura-claims-with-actions/71790 "2021-10-21T15:03:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ulisses](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ulisses/32/12811_2.png) [@ulisses](https://community.auth0.com/u/ulisses)\
**Post date:** [October 21, 2021, 3:03pm UTC](https://community.auth0.com/t/adding-hasura-claims-with-actions/71790/1 "2021-10-21T15:03:22Z")

</div>

Hasura docs show how to integrate Auth0 JWT with it’s graphql api.

> **[Auth0 JWT Integration with Hasura GraphQL Engine | Hasura GraphQL Docs](https://hasura.io/docs/latest/auth/authentication/integrations/auth0-jwt/)**
>
> Integrate Auth0 JWT with Hasura

But they are using Rules to add the claims.  
It looks like Auth0 is recommending Actions now.

I tried to make add the claims using actions but it is not working, **I don’t see the custom claims** in the token:

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

```

I’ve attached this to the **Machine to Machine** flow.  
What am I missing?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 21, 2021, 6:21pm UTC](https://community.auth0.com/t/adding-hasura-claims-with-actions/71790/3 "2021-10-21T18:21:00Z")

</div>

Hi @ulisses,

Welcome to the Auth0 Community!

I understand that you are looking to add Hasura claims with Actions.

First, I’d like to emphasize that [Rules](https://auth0.com/docs/rules/create-rules#how-rules-work) are triggered after a user authenticates to your application.

In other words, this would be equivalent to a Post-Login Action. In the Hasura documentation, they are adding custom claims to the accessToken like this [example](https://auth0.com/docs/configure/apis/scopes/sample-use-cases-scopes-and-claims#add-custom-claims-to-a-token).

To accomplish this with Actions, you’ll need to use a [Post-Login Action](https://auth0.com/docs/actions/triggers/post-login#add-user-roles-to-tokens) script to add the Hasura claims to tokens and pass the `event.user.user_id` as the user’s ID.

For example:

```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
    });
};

```

You may also find these resources useful:  
[https://auth0.com/docs/actions/triggers/post-login/event-object](https://auth0.com/docs/actions/triggers/post-login/event-object)  
[https://auth0.com/docs/actions/triggers/post-login/api-object](https://auth0.com/docs/actions/triggers/post-login/api-object)

Please let me know how this works for you.

Thank you.

---

<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:** [November 5, 2021, 6:21pm UTC](https://community.auth0.com/t/adding-hasura-claims-with-actions/71790/4 "2021-11-05T18:21:11Z")

</div>

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