# Action Trigger on login does not add custom field email to acces token

**URL:** <https://community.auth0.com/t/action-trigger-on-login-does-not-add-custom-field-email-to-acces-token/73054>\
**Category:** Get Help\
**Tags:** jwt, auth0\
**Created:** [November 12, 2021, 3:29pm UTC](https://community.auth0.com/t/action-trigger-on-login-does-not-add-custom-field-email-to-acces-token/73054 "2021-11-12T15:29:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev30](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dev30/32/12814_2.png) [@dev30](https://community.auth0.com/u/dev30)\
**Post date:** [November 12, 2021, 3:29pm UTC](https://community.auth0.com/t/action-trigger-on-login-does-not-add-custom-field-email-to-acces-token/73054/1 "2021-11-12T15:29:57Z")

</div>

I configured my action trigger - on login like that:

```auto
exports.onExecutePostLogin = async (event, api) => {
  api.accessToken.setCustomClaim('email', event.user.email);
};

```

I deployed it and add it to the flow. In logs everything is fine. I successfully made a post registration action but login action actually doesn’t modify access token.  
So to be confident that I test it correctly I’ ve added a similar rule:

```auto
function addEmailToAccessToken(user, context, callback) {
  context.accessToken['email'] = user.email;
  return callback(null, user, context);
}

```

And it works great.  
I think it’s some kind of a bug of an action trigger functionality.

---

<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:** [November 12, 2021, 5:33pm UTC](https://community.auth0.com/t/action-trigger-on-login-does-not-add-custom-field-email-to-acces-token/73054/3 "2021-11-12T17:33:46Z")

</div>

Hi @dev30,

Thanks for reaching out to the Auth0 Community!

I understand that you’re having issues getting the Post-Login Action script to append custom claims to your access token.

After looking at your code snippet, it appears that you did not specify a _namespace_ to append your custom claim. Read [Create Custom Claims](https://auth0.com/docs/security/tokens/json-web-tokens/create-namespaced-custom-claims) for more details.

Given that, I recommend that you do something like the following in your Post Login Action script:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.accessToken.setCustomClaim(`${namespace}/email`, event.user.email);
  }
};

```

There is also a [add user roles to tokens](https://auth0.com/docs/actions/triggers/post-login#add-user-roles-to-tokens) example use-case which you might find helpful.

Hoped this helps!

Please let me know if you have any further questions.

Thank you.

---

<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 27, 2021, 5:34pm UTC](https://community.auth0.com/t/action-trigger-on-login-does-not-add-custom-field-email-to-acces-token/73054/4 "2021-11-27T17:34:20Z")

</div>

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