# Alternative to using rule to attach email to access tokens

**URL:** <https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [November 28, 2023, 9:07pm UTC](https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853 "2023-11-28T21:07:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [November 28, 2023, 9:29pm UTC](https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853/3 "2023-11-28T21:29:33Z")

</div>

Hello @jmdot welcome to the community!

> [@jmdot](#):
>
> what would the alternative using an action be for this?

Similar to a rule, you will just need to add `email` as a custom claim using an Action - A [Post Login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) should work for this and look like the following:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com/';
  const email = event.user.email;

  if (email) {
    api.accessToken.setCustomClaim(`${namespace}email`, email);
  }
};

```

Since `email` is not a [restricted claim](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#non-restricted-claims) you can also forego using a namespace:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const email = event.user.email;

  if (email) {
    api.accessToken.setCustomClaim('email', email);
  }
};

```

---

_[View the full topic](https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853)._
