# Can only seem to set custom claim on id token not access token

**URL:** <https://community.auth0.com/t/can-only-seem-to-set-custom-claim-on-id-token-not-access-token/113583>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [August 14, 2023, 1:46pm UTC](https://community.auth0.com/t/can-only-seem-to-set-custom-claim-on-id-token-not-access-token/113583 "2023-08-14T13:46:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![baynezy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/baynezy/32/49885_2.png) [@baynezy](https://community.auth0.com/u/baynezy)\
**Post date:** [August 14, 2023, 1:46pm UTC](https://community.auth0.com/t/can-only-seem-to-set-custom-claim-on-id-token-not-access-token/113583/1 "2023-08-14T13:46:22Z")

</div>

I have the following PostLogin action:

```javascript
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
  var profileId = event.user.app_metadata.profileId;
  api.idToken.setCustomClaim("profileId", profileId);
  api.accessToken.setCustomClaim("profileId", profileId);
};

```

It sets the claim on the ID Token with no problem, but my access token has no custom claims.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![baynezy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/baynezy/32/49885_2.png) [@baynezy](https://community.auth0.com/u/baynezy)\
**Post date:** [August 14, 2023, 3:22pm UTC](https://community.auth0.com/t/can-only-seem-to-set-custom-claim-on-id-token-not-access-token/113583/2 "2023-08-14T15:22:09Z")

</div>

So I got it working by adding a namespace prefix:-

```javascript
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
  const nameSpace = "https://my-domain.com/";
  var profileId = event.user.app_metadata.profileId;
  api.idToken.setCustomClaim("profileId", profileId);
  api.accessToken.setCustomClaim(nameSpace + "profileId", profileId);
};

```

It would be helpful if you could see these issues in the logs somewhere.

---

<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:** [August 28, 2023, 3:22pm UTC](https://community.auth0.com/t/can-only-seem-to-set-custom-claim-on-id-token-not-access-token/113583/3 "2023-08-28T15:22:41Z")

</div>

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