# Help with custom action is needed

**URL:** <https://community.auth0.com/t/help-with-custom-action-is-needed/122852>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [December 11, 2023, 8:52pm UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852 "2023-12-11T20:52:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![raymond.lee](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@raymond.lee](https://community.auth0.com/u/raymond.lee)\
**Post date:** [December 11, 2023, 8:52pm UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852/1 "2023-12-11T20:52:25Z")

</div>

We have two simple rules that run on all our tenants when a user logs in. However, since AUTH-PIPELINE-RULES is not available in the newly created tenants, I want to know how I can convert them into custom action and achieve the same function. I have tried reading the documentation, but I still can’t grasp it. I hope someone can provide me with some assistance.

Rule # 1

function (user, context, callback) {  
const namespace = ‘[https://myapp.com/](https://myapp.com/)’;  
context.accessToken[namespace + ‘email’] = user.email;  
callback(null, user, context);  
}

Rule #2

The value configuration.intercom\_key is defined under the rules as an encrypted key object currently on AUTH0 old tenant.

function (user, context, callback) {  
const namespace = ‘[https://myapp.com/](https://myapp.com/)’;  
const crypto = require(‘crypto’);  
const hmac = crypto.createHmac(‘sha256’, configuration.intercom\_key);

hmac.update(user.email);

const hash = hmac.digest(‘hex’);

context.idToken[namespace + ‘intercom\_hash’] = hash;  
context.accessToken[namespace + ‘intercom\_hash’] = hash;  
callback(null, user, context);  
}

Thanks in advance!

---

<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 12, 2023, 1:36am UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852/3 "2023-12-12T01:36:35Z")

</div>

Hey there @raymond.lee !

You’ll want to test these thoroughly, but I’ve converted these to Actions you can go off of:

Action # 1

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

  const namespace = 'https://myapp.com/';
  api.accessToken.setCustomClaim(namespace + 'email', event.user.email);
};

```

Action # 2

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

    const namespace = 'https://myapp.com/';
    const crypto = require('crypto');
    const hmac = crypto.createHmac('sha256', event.secrets.intercom_key);

    hmac.update(event.user.email);
    const hash = hmac.digest('hex');

    api.idToken.setCustomClaim(namespace + 'intercom_hash', hash);
    api.accessToken.setCustomClaim(namespace + 'intercom_hash', hash);
};

```

A couple things to note with Action # 2 is that I have added `intercom` to [event.secrets](https://auth0.com/docs/customize/actions/write-your-first-action#add-a-secret) and had to suppress errors associated with passing `event.user.email` to `hmac.update()` - These were just in relation to `event.user.email` potentially being `undefined`.

---

<div class="post-metadata">

**Author:** ![raymond.lee](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@raymond.lee](https://community.auth0.com/u/raymond.lee)\
**Post date:** [December 12, 2023, 2:05am UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852/4 "2023-12-12T02:05:19Z")

</div>

Hi tyf, Thanks for your help and definitely will try it out.

---

<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 12, 2023, 4:11pm UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852/5 "2023-12-12T16:11:24Z")

</div>

No problem @raymond.lee happy to help! Keep us posted 🙂

---

<div class="post-metadata">

**Author:** ![raymond.lee](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@raymond.lee](https://community.auth0.com/u/raymond.lee)\
**Post date:** [December 12, 2023, 5:13pm UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852/6 "2023-12-12T17:13:27Z")

</div>

Hi Tyf,

It works like a charm after I added those two new create actions inside the FLOWS - LOGIN. I missed that at the beginning.

Thank you so much for your help; it’s greatly appreciated!!!

---

<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 12, 2023, 9:56pm UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852/7 "2023-12-12T21:56:12Z")

</div>

That’s great news - Happy to help! 🙂

---

<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:** [December 26, 2023, 9:56pm UTC](https://community.auth0.com/t/help-with-custom-action-is-needed/122852/8 "2023-12-26T21:56:52Z")

</div>

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