# How to add email to access token using auth0 action Post-login event

**URL:** <https://community.auth0.com/t/how-to-add-email-to-access-token-using-auth0-action-post-login-event/119873>\
**Category:** Get Help\
**Tags:** emails, management-api\
**Created:** [October 31, 2023, 2:37pm UTC](https://community.auth0.com/t/how-to-add-email-to-access-token-using-auth0-action-post-login-event/119873 "2023-10-31T14:37:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ncmohite](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ncmohite/32/52106_2.png) [@ncmohite](https://community.auth0.com/u/ncmohite)\
**Post date:** [October 31, 2023, 2:37pm UTC](https://community.auth0.com/t/how-to-add-email-to-access-token-using-auth0-action-post-login-event/119873/1 "2023-10-31T14:37:37Z")

</div>

I want to add the user’s email to my API access token. earlier using rules we used to do this but now since rules deprecated we have to add actions so i have created a Post-Login Action to do so:  
below is the code for it i have added

```auto
exports.onExecutePostLogin = async (event, api) => {
  // This rule adds the authenticated user's email address to the access token.

    // This rule adds the authenticated user's email address to the access token.
  if (event.authorization) {
  const namespace = 'https://thepickleballwizard.com';
    api.accessToken[`${namespace}/email`] = event.user.email;
  }
};

```

above code not adding any email to access token what i am missing

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mraible/32/32776_2.png) [@mraible](https://community.auth0.com/u/mraible)\
**Post date:** [October 31, 2023, 5:59pm UTC](https://community.auth0.com/t/how-to-add-email-to-access-token-using-auth0-action-post-login-event/119873/3 "2023-10-31T17:59:28Z")

</div>

You need to use `setCustomClaim()`. Here’s how to do it for both your ID and access tokens:

```js
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://thepickleballwizard.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/email`, event.user.email);
    api.accessToken.setCustomClaim(`${namespace}/email`, event.user.email);
  }
}
```

---

<div class="post-metadata">

**Author:** ![ncmohite](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ncmohite/32/52106_2.png) [@ncmohite](https://community.auth0.com/u/ncmohite)\
**Post date:** [November 1, 2023, 5:48am UTC](https://community.auth0.com/t/how-to-add-email-to-access-token-using-auth0-action-post-login-event/119873/4 "2023-11-01T05:48:59Z")

</div>

yes its worked thanks for the 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:** [November 15, 2023, 5:49am UTC](https://community.auth0.com/t/how-to-add-email-to-access-token-using-auth0-action-post-login-event/119873/5 "2023-11-15T05:49:29Z")

</div>

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