# Post-Login Action not adding email to access token

**URL:** <https://community.auth0.com/t/post-login-action-not-adding-email-to-access-token/97804>\
**Category:** Get Help\
**Tags:** custom-claims, actions, access-token\
**Created:** [January 10, 2023, 3:32am UTC](https://community.auth0.com/t/post-login-action-not-adding-email-to-access-token/97804 "2023-01-10T03:32:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweet](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sweet/32/42458_2.png) [@sweet](https://community.auth0.com/u/sweet)\
**Post date:** [January 10, 2023, 3:32am UTC](https://community.auth0.com/t/post-login-action-not-adding-email-to-access-token/97804/1 "2023-01-10T03:32:20Z")

</div>

I want to add the user’s email as a custom claim on my API access token. Following [these instructions](https://community.auth0.com/t/i-cant-add-the-user-email-on-access-token/83958), I created a Post-Login Action to do so:

```auto
exports.onExecutePostLogin = async (event, api) => {
    // This adds the authenticated user's email address to the access token.
  if (event.authorization) {
    const namespace = 'https://dev-hnvbea5l8bn2ww66.us.auth0.com'; // this is my token issuer
    api.accessToken.setCustomClaim(`${namespace}/claims/email`, event.user.email);
  }
};

```

 ![Screenshot 2023-01-09 at 9.52.22 PM](https://global.discourse-cdn.com/auth0/original/3X/3/b/3bf44c0f375e3f5b1075d13954f3ab401d8f41ad.png)

The test doesn’t allow me to see what the modified access token will look like, like Rules tests did, but all seems ok here:

 ![Screenshot 2023-01-09 at 9.54.53 PM](https://global.discourse-cdn.com/auth0/original/3X/9/d/9daa9278c7d78be60dcc56ba9b74eaafb322c565.png)

The Action is included in the Login flow:

 ![Screenshot 2023-01-09 at 9.55.36 PM](https://global.discourse-cdn.com/auth0/original/3X/f/c/fc4539aa3d4699de1f6184cd86d6f7b9d6302f9c.png)

But when I get an access token, either using cURL or getAccessTokenSilently, it doesn’t include the custom claim:

 ![Screenshot 2023-01-09 at 10.06.13 PM](https://global.discourse-cdn.com/auth0/original/3X/2/8/2862cc41494a80dda56a13c1ed6075db3a31d907.png)

I see that the Action runs in the logs for login events, but it doesn’t appear to run for credential-token exchanges.

 ![Screenshot 2023-01-09 at 10.26.59 PM](https://global.discourse-cdn.com/auth0/original/3X/a/6/a693cadf7f1183e59107f19fe65ceb8933df09b6.png)

 ![Screenshot 2023-01-09 at 10.00.40 PM](https://global.discourse-cdn.com/auth0/original/3X/8/2/8269ecae59af0cfc11bee6f1d204aa818d83bb50.png)

 ![Screenshot 2023-01-09 at 10.02.14 PM](https://global.discourse-cdn.com/auth0/original/3X/3/3/338d16567916af96e3b98a8e47e09a20085e4b33.png)

How can I fix this and get the custom claim added to the access token fetched via getAccessTokenSilently, which is what I really need the email added to?

---

<div class="post-metadata">

**Author:** ![eric.culley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eric.culley/32/37008_2.png) [@eric.culley](https://community.auth0.com/u/eric.culley)\
**Post date:** [January 11, 2023, 12:14am UTC](https://community.auth0.com/t/post-login-action-not-adding-email-to-access-token/97804/3 "2023-01-11T00:14:32Z")

</div>

Hi @sweet

It appears that you’re using a restricted namespace format. Our documentation states the following:

> Use any non-Auth0 HTTP or HTTPS URL as a namespace identifier. Auth0 domains cannot be used as namespace identifiers, and include [auth0.com](http://auth0.com)

Try updating your namespace variable to a value that does not include ‘[auth0.com](http://auth0.com)’.

> **[Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines)**
>
> Learn how to create collision-resistant names for custom claims.

---

<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:** [January 25, 2023, 12:15am UTC](https://community.auth0.com/t/post-login-action-not-adding-email-to-access-token/97804/4 "2023-01-25T00:15:20Z")

</div>

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