# Not able to add email in access token claim

**URL:** <https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772>\
**Category:** Get Help\
**Tags:** login-prompt-new-experience, login-experience\
**Created:** [March 15, 2024, 4:40pm UTC](https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772 "2024-03-15T16:40:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachinsharma123](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sachinsharma123/32/55663_2.png) [@sachinsharma123](https://community.auth0.com/u/sachinsharma123)\
**Post date:** [March 15, 2024, 4:40pm UTC](https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772/1 "2024-03-15T16:40:51Z")

</div>

Hi,

I am trying following code with passwordless flow to add email to access token claim:  
exports.onExecutePostLogin = async (event, api) =\> {  
// This action adds the authenticated user’s email address to the access token.

```
let namespace = event.secrets.NAMESPACE || '';
if (namespace && !namespace.endsWith('/')) {
    namespace += '/';
}

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

```

};  
But it doesn’t seem to be working. Could see this coming as event object:  
{\n transaction: { protocol: ‘oauth2-password’ },\n authentication: undefined,\n authorization: { roles: },\n connection: {\n id: ‘con\_waSHQv3KhaErYGTw’,\n metadata: {},\n name: ‘email’,\n strategy: ‘email’\n },\n organization: undefined,"

user object is missing.  
Does it even work with passwordless flow or did i miss anything?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 15, 2024, 7:19pm UTC](https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772/3 "2024-03-15T19:19:29Z")

</div>

Hi @sachinsharma123,

Welcome to the Auth0 Community!

Yes, the Passwordless flow will trigger the post-login action flow.

Firstly, please make sure that your namespace adheres to the namespace guidelines listed [here](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines).

Then please refer to [this knowledge solution](https://community.auth0.com/t/adding-custom-claims-to-tokens/84590) for an example of adding custom claims to tokens.

Once that’s done, you can verify that it works by logging in and decoding your access token on [jwt.io](http://jwt.io) to see the payload containing the email custom claim.

Let me know how this goes for you.

Cheers,  
Rueben

---

<div class="post-metadata">

**Author:** ![sachinsharma123](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sachinsharma123/32/55663_2.png) [@sachinsharma123](https://community.auth0.com/u/sachinsharma123)\
**Post date:** [March 18, 2024, 9:52am UTC](https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772/4 "2024-03-18T09:52:58Z")

</div>

Hi,

I followed the link which you shared didn’t help me resolving the issue. I have logged the event object for the action and i don’t see user object in this. Am I missing something:  
{  
“action\_name”: “add-email-to-access-token”,  
“response”: {  
“logs”: “Sachin {\n transaction: { protocol: ‘oauth2-password’ },\n authentication: undefined,\n authorization: { roles: },\n connection: {\n id: ‘con\_waSHQv3KhaErYGTw’,\n metadata: {},\n name: ‘email’,\n strategy: ‘email’\n },\n organization: undefined,”,  
“stats”: {  
“total\_request\_duration\_ms”: 410,  
“total\_runtime\_execution\_duration\_ms”: 406,  
“runtime\_processing\_duration\_ms”: 5,  
“action\_duration\_ms”: 328,  
“runtime\_external\_call\_duration\_ms”: 73,  
“boot\_duration\_ms”: 78,  
“network\_duration\_ms”: 5  
}  
},  
“started\_at”: “2024-03-18T09:48:52.259496391Z”,  
“ended\_at”: “2024-03-18T09:48:52.670927130Z”  
}

Also i want to add user email to access token. Can you please share any example specific to that usecase as to how i can get hold of user email.

---

<div class="post-metadata">

**Author:** ![sachinsharma123](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sachinsharma123/32/55663_2.png) [@sachinsharma123](https://community.auth0.com/u/sachinsharma123)\
**Post date:** [March 18, 2024, 10:16am UTC](https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772/5 "2024-03-18T10:16:05Z")

</div>

sorry, it worked. Thanks for your help

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 18, 2024, 11:54pm UTC](https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772/6 "2024-03-18T23:54:37Z")

</div>

Hi @sachinsharma123,

I’m glad to here that it worked!

Please reach out again if you have any additional questions.

Thanks,  
Rueben

---

<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:** [April 1, 2024, 11:55pm UTC](https://community.auth0.com/t/not-able-to-add-email-in-access-token-claim/129772/7 "2024-04-01T23:55:04Z")

</div>

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