# Rules adds email to custom claims, but not working with actions

**URL:** <https://community.auth0.com/t/rules-adds-email-to-custom-claims-but-not-working-with-actions/115871>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [September 11, 2023, 3:00am UTC](https://community.auth0.com/t/rules-adds-email-to-custom-claims-but-not-working-with-actions/115871 "2023-09-11T03:00:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KLP](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/klp/32/49127_2.png) [@KLP](https://community.auth0.com/u/KLP)\
**Post date:** [September 11, 2023, 3:00am UTC](https://community.auth0.com/t/rules-adds-email-to-custom-claims-but-not-working-with-actions/115871/1 "2023-09-11T03:00:35Z")

</div>

Here’s my rule -

```auto
function addEmailToAccessToken(user, context, callback) {
  // This rule adds the authenticated user's email address to the access token.

  var namespace = 'https://logkeeper.com/';

  context.accessToken[namespace + 'email'] = user.email;
  return callback(null, user, context);
}

```

Here’s my action:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://logkeeper.com/'

  api.accessToken.setCustomClaim(namespace + 'email', event.user.email)
};

```

The action doesn’t work, but the rule works fine.

What’s going on?

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [September 12, 2023, 12:35pm UTC](https://community.auth0.com/t/rules-adds-email-to-custom-claims-but-not-working-with-actions/115871/2 "2023-09-12T12:35:22Z")

</div>

Hey @KLP ,

I tried to reproduce your issue, and did the following:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com';
    // Set a claim 
    api.accessToken.setCustomClaim(`${namespace}/preferred_contact`, event.user.email);
  };

```

And I got the token with the custom claim and value:  
`"https://myapp.example.com/preferred_contact": "marcelina.bxxx@xxx.com",`

 ![image](https://global.discourse-cdn.com/auth0/original/3X/6/6/668e5406c7f5a0340b0e8078c35f2fcaaa6a83d4.png)

Can you please try in a similar way? Thanks!

---

<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:** [September 26, 2023, 12:35pm UTC](https://community.auth0.com/t/rules-adds-email-to-custom-claims-but-not-working-with-actions/115871/3 "2023-09-26T12:35:33Z")

</div>

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