# Rules to actions migration, idToken claim not being passed through

**URL:** <https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [May 23, 2024, 12:26pm UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837 "2024-05-23T12:26:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tibotiber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tibotiber/32/57348_2.png) [@tibotiber](https://community.auth0.com/u/tibotiber)\
**Post date:** [May 23, 2024, 12:26pm UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/1 "2024-05-23T12:26:00Z")

</div>

Hi, I’m trying to migrate from rules to actions. The guide was pretty great and I think i’ve got everything good to go. However my idToken is not being set anymore.

Here is the rule I was using:

```js
function(user, context, callback) {
  const fetch = require('node-fetch');
  // call our login lambda
  fetch('https://mydomain/i/login', {
    method: 'POST',
    headers: { authorization: configuration.MYTOKEN },
    body: JSON.stringify({ user }),
    timeout: 15000
  })
  .then(res => {
    if (!res.ok) {
      res.json().then((errorData) => {
        // non 2xx status code
        console.log('ERROR', errorData);
        return callback(new Error(errorData));
      });
    }
    res.json().then((data) => {
      const { smplrspace, hasura } = data;
      // add custom data
      const smplrNamespace = "https://smplrspace.com/jwt/claims";
      context.idToken[smplrNamespace] = smplrspace;
      // add hasura token
      const hasuraNamespace = "https://hasura.io/jwt/claims";
      context.accessToken[hasuraNamespace] = hasura;
      // finish
      console.log(`Login: ${user.name} (${user.email})`);
      callback(null, user, context);
    });
  })
  .catch(error => {
    console.log('ERROR', error);
    return callback(new Error(error));
  });
}

```

and here is the action code:

```js
const fetch = require('node-fetch') // version 2.6.1

exports.onExecutePostLogin = async (event, api) => {
  // call our login lambda
  fetch('https://mydomain/i/login', {
    method: 'POST',
    headers: { authorization: event.secrets.MYTOKEN },
    body: JSON.stringify({ user: event.user }),
    timeout: 15000,
  })
    .then((res) => {
      if (!res.ok) {
        res.json().then((error) => {
          // non 2xx status code
          console.log('ERROR', error)
          return api.access.deny(error.message)
        })
      }
      res.json().then((data) => {
        const { smplrspace, hasura } = data
        // add custom data
        const smplrNamespace = 'https://smplrspace.com/jwt/claims'
        api.idToken.setCustomClaim(smplrNamespace, smplrspace)
        // add hasura token
        const hasuraNamespace = 'https://hasura.io/jwt/claims'
        api.accessToken.setCustomClaim(hasuraNamespace, hasura)
        // finish
        console.log(`Login: ${event.user.name} (${event.user.email})`)
        return
      })
    })
    .catch((error) => {
      console.log('ERROR', error)
      return api.access.deny(error.message)
    })
}

```

The idToken appears unmodified in my frontend code (no changes there). Any idea?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tibotiber/32/57348_2.png) [@tibotiber](https://community.auth0.com/u/tibotiber)\
**Post date:** [May 31, 2024, 3:37am UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/3 "2024-05-31T03:37:22Z")

</div>

Hi, any help? Is there any support we can reach out to? If not, how to migrate?

---

<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 6, 2024, 7:54pm UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/4 "2024-06-06T19:54:41Z")

</div>

Hey there @tibotiber!

Sorry for the delayed response here, but wanted to see if you were able to get this sorted? Is custom claim added reliably?

If your subscription allows for it, you can always open up a ticket at [https://support.auth0.com/](https://support.auth0.com/)

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tibotiber/32/57348_2.png) [@tibotiber](https://community.auth0.com/u/tibotiber)\
**Post date:** [June 7, 2024, 12:37am UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/5 "2024-06-07T00:37:06Z")

</div>

Hi @ty.frith thanks for reaching out. No I haven’t solved this yet. Any help would be welcome 🙂

---

<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 7, 2024, 2:49pm UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/6 "2024-06-07T14:49:22Z")

</div>

Happy to help!

```auto
  res.json().then((data) => {
        const { smplrspace, hasura } = data
        // add custom data
        const smplrNamespace = 'https://smplrspace.com/jwt/claims'
        api.idToken.setCustomClaim(smplrNamespace, smplrspace)
        // add hasura token
        const hasuraNamespace = 'https://hasura.io/jwt/claims'
        api.accessToken.setCustomClaim(hasuraNamespace, hasura)
        // finish
        console.log(`Login: ${event.user.name} (${event.user.email})`)
        return
      })

```

Is the access token custom claim set consistently in the same `.then()` where the ID token custom claim isn’t? Nothing in particular stands out in your code, but I’m wondering if it’s an issue with the nested `.then()` statements and an early return.

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tibotiber/32/57348_2.png) [@tibotiber](https://community.auth0.com/u/tibotiber)\
**Post date:** [June 10, 2024, 5:07am UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/7 "2024-06-10T05:07:20Z")

</div>

Seeing the length of the response alone, the access token claim is also not set.

Your comment about an early return was a great lead, I’ve switched to using `async/await` instead of `.then()` as it’s a lot clearer what happens and it fixed my issue 🎉. I’m guessing the rules used an explicit call to the callback while an implicit return could end execution in an action, or something like that 🤷‍♂️.

Thanks a lot for the help @ty.frith 🙏. Truly appreciate it 🙂.

In case it helps anyone in future, here is the working code:

```auto
const fetch = require('node-fetch'); // version 2.6.1

exports.onExecutePostLogin = async (event, api) => {
  // call our login lambda
  try {
    const res = await fetch('https://mydomain/i/login', {
      method: 'POST',
      headers: { authorization: event.secrets.MYTOKEN },
      body: JSON.stringify({ user: event.user }),
      timeout: 15000
    });
    if (!res.ok) {
      // non 2xx status code
      const error = await res.json();
      console.log('ERROR', error);
      return api.access.deny(error.message);
    }
    const { smplrspace, hasura } = await res.json();
    // add custom data
    const smplrNamespace = "https://smplrspace.com/jwt/claims";
    api.idToken.setCustomClaim(smplrNamespace, smplrspace);
    // add hasura token
    const hasuraNamespace = "https://hasura.io/jwt/claims";
    api.accessToken.setCustomClaim(hasuraNamespace, hasura);
    // finish
    console.log(`Login: ${event.user.name} (${event.user.email})`);
    return;
  } catch (error) {
    console.log('ERROR', error);
    return api.access.deny(error.message);
  }
};

```

✌

---

<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, 2:51pm UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/8 "2024-06-10T14:51:33Z")

</div>

Awesome! I’m glad `async/await` did the trick 🙂 Thanks for sharing the working code, very helpful! 🙏

---

<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, 2:51pm UTC](https://community.auth0.com/t/rules-to-actions-migration-idtoken-claim-not-being-passed-through/134837/9 "2024-06-24T14:51:38Z")

</div>

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