# How to convert Rule to Action

**URL:** <https://community.auth0.com/t/how-to-convert-rule-to-action/95994>\
**Category:** Get Help\
**Tags:** other, test\
**Created:** [December 8, 2022, 8:29am UTC](https://community.auth0.com/t/how-to-convert-rule-to-action/95994 "2022-12-08T08:29:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovannilaperna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giovannilaperna/32/34414_2.png) [@giovannilaperna](https://community.auth0.com/u/giovannilaperna)\
**Post date:** [December 8, 2022, 8:29am UTC](https://community.auth0.com/t/how-to-convert-rule-to-action/95994/1 "2022-12-08T08:29:37Z")

</div>

I’ve read that Rules will be soon deprecated and should be replaced with Actions.

I’ve a very simple rule that I don’t know how to convert.

This is the rule:

```auto
function (user, context, callback) {
  context.accessToken['http://localhost:3000/whatsapp'] = user.name;
  callback(null, user, context);
}

```

Is this the correct equivalent Action?

```auto
exports.onExecutePostLogin = async (event, api) => {
  event.context.accessToken['http://localhost:3000/whatsapp'] = event.user.name;
};

```

---

<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:** [December 9, 2022, 12:34am UTC](https://community.auth0.com/t/how-to-convert-rule-to-action/95994/3 "2022-12-09T00:34:25Z")

</div>

Hello @giovannilaperna welcome back!

Your Action should look like the following:

```auto
exports.onExecutePostLogin = async (event, api) => {
    api.accessToken.setCustomClaim('http://localhost:3000/whatsapp', event.user.name);
}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![giovannilaperna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giovannilaperna/32/34414_2.png) [@giovannilaperna](https://community.auth0.com/u/giovannilaperna)\
**Post date:** [December 9, 2022, 6:11am UTC](https://community.auth0.com/t/how-to-convert-rule-to-action/95994/4 "2022-12-09T06:11:57Z")

</div>

For some reason that didn’t work.  
I had to set a public claim on my domain and use it also on localhost.

```auto
exports.onExecutePostLogin = async (event, api) => {

  api.accessToken.setCustomClaim('https://MY-DOMAIN/whatsapp', event.user.name);
  api.accessToken.setCustomClaim('https://MY-DOMAIN/loginsCount', event.stats.logins_count);
};

```

---

<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:** [December 9, 2022, 11:11pm UTC](https://community.auth0.com/t/how-to-convert-rule-to-action/95994/5 "2022-12-09T23:11:30Z")

</div>

Thanks for following up!

That’s interesting 🤔 Regardless, goo to know you got it working 😄

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 21, 2022, 3:25pm UTC](https://community.auth0.com/t/how-to-convert-rule-to-action/95994/6 "2022-12-21T15:25:17Z")

</div>


