# Add data on Access Token - avoid Rules and Hooks

**URL:** <https://community.auth0.com/t/add-data-on-access-token-avoid-rules-and-hooks/107843>\
**Category:** JWT.io\
**Tags:** id\_token, access-token, login, auth0\
**Created:** [May 25, 2023, 6:56pm UTC](https://community.auth0.com/t/add-data-on-access-token-avoid-rules-and-hooks/107843 "2023-05-25T18:56:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![douglas.freitas](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@douglas.freitas](https://community.auth0.com/u/douglas.freitas)\
**Post date:** [May 25, 2023, 6:56pm UTC](https://community.auth0.com/t/add-data-on-access-token-avoid-rules-and-hooks/107843/1 "2023-05-25T18:56:28Z")

</div>

Hi Team,

I receive an email inform the Rules and Hooks will be discontinued.  
I use Rule to add user data on ID\_TOKEN. How I can add custom information on ID\_TOKEN?

Sample fo Rule:

function (user, context, callback) {  
// This rule adds user\_metadata to idToken.  
context.idToken[‘user.metadata’] = {  
“custom\_data\_1”: user.user\_metadata.custom\_data\_1  
};  
return callback(null, user, context);  
}

---

<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:** [May 25, 2023, 8:51pm UTC](https://community.auth0.com/t/add-data-on-access-token-avoid-rules-and-hooks/107843/3 "2023-05-25T20:51:57Z")

</div>

Hi @douglas.freitas,

Welcome to the Auth0 Community!

Yes, that is correct! We recently made an announcement that Rules and Hooks is reaching the end of life:

> [@Rules and Hooks nearing End of Life](https://community.auth0.com/t/rules-and-hooks-nearing-end-of-life/107038):
>
> Hello, everyone! To improve our extensibility offering, we will be deprecating Rules and Hooks as an option for both customers and partners in November 2024 and will be unifying all of our extensibility features under Actions. We will start removing Hooks access from new tenants/new customers in the coming weeks. What action do you need to take? If you’re able to make the migration to Actions now, we highly recommend doing so. To help with the migration process, we have documentation on [migra…](https://auth0.com/docs/customize/actions/migrate/migrate-from-hooks-to-actions)

Now, in this situation, what you will need to do is convert your existing Rule to a Post Login Action.

For your convenience, I have converted your Rule into a Post Action code snippet below:

```auto
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.example.com';
  if (event.authorization) {
    // Set claims
    api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata.custom_data_1);
  }
};

```

To assist you further, I’ve also gathered some helpful resources that you can refer to:

- [Adding Custom Claims to Tokens](https://community.auth0.com/t/adding-custom-claims-to-tokens/84590)
- [Migration Guide: Rules to Actions](https://auth0.com/docs/customize/actions/migrate)

Please let me know if there is anything else I can do to help!

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![douglas.freitas](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@douglas.freitas](https://community.auth0.com/u/douglas.freitas)\
**Post date:** [May 26, 2023, 11:45am UTC](https://community.auth0.com/t/add-data-on-access-token-avoid-rules-and-hooks/107843/4 "2023-05-26T11:45:40Z")

</div>

Thank you Rueben!

I will test with your sample and read more in references!

Best regards

---

<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:** [May 26, 2023, 6:10pm UTC](https://community.auth0.com/t/add-data-on-access-token-avoid-rules-and-hooks/107843/5 "2023-05-26T18:10:18Z")

</div>

Hi @douglas.freitas,

Of course, you’re welcome!

Regards,  
Rueben

---

<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 9, 2023, 6:11pm UTC](https://community.auth0.com/t/add-data-on-access-token-avoid-rules-and-hooks/107843/6 "2023-06-09T18:11:20Z")

</div>

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