# 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:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmdot](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jmdot](https://community.auth0.com/u/jmdot)\
**Post date:** [November 28, 2023, 9:07pm UTC](https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853/1 "2023-11-28T21:07:44Z")

</div>

I’m currently using the rule to attach an access token but I’ve seen that rules are going to be deprecated, what would the alternative using an action be for this?

---

<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);
  }
};

```

---

<div class="post-metadata">

**Author:** ![jmdot](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jmdot](https://community.auth0.com/u/jmdot)\
**Post date:** [December 1, 2023, 1:08pm UTC](https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853/4 "2023-12-01T13:08:24Z")

</div>

Awesome, thank you very much I’m going to give this a shot.

I’m facing another similar challenge, I currently have a rule which runs after users signup in order to create user accounts in our database. We want to replace this with an action but when we tried we noticed that actions aren’t being triggered when a user does a social sign up. What is the alternative route that we should take as we’re aware that rules will be being replaced next year which will break this functionality that we require?

---

<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 4, 2023, 9:43pm UTC](https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853/5 "2023-12-04T21:43:00Z")

</div>

Hey @jmdot no problem, happy to help!

> [@jmdot](#):
>
> We want to replace this with an action but when we tried we noticed that actions aren’t being triggered when a user does a social sign up. What is the alternative route that we should take as we’re aware that rules will be being replaced next year which will break this functionality that we require?

Neither Pre nor Post Registration Actions will run for Social connections - You will need to look into using a Post Login Action instead.

[https://community.auth0.com/t/actions-not-triggered-with-social-login/98982](https://community.auth0.com/t/actions-not-triggered-with-social-login/98982)

---

<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 18, 2023, 9:43pm UTC](https://community.auth0.com/t/alternative-to-using-rule-to-attach-email-to-access-tokens/121853/6 "2023-12-18T21:43:33Z")

</div>

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