# Is it possible to assign a custom claim to a JWT token on signup using flows?

**URL:** <https://community.auth0.com/t/is-it-possible-to-assign-a-custom-claim-to-a-jwt-token-on-signup-using-flows/64530>\
**Category:** Get Help\
**Tags:** actions\
**Created:** [June 15, 2021, 2:37pm UTC](https://community.auth0.com/t/is-it-possible-to-assign-a-custom-claim-to-a-jwt-token-on-signup-using-flows/64530 "2021-06-15T14:37:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eosn-fred](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eosn-fred/32/12732_2.png) [@eosn-fred](https://community.auth0.com/u/eosn-fred)\
**Post date:** [June 15, 2021, 2:37pm UTC](https://community.auth0.com/t/is-it-possible-to-assign-a-custom-claim-to-a-jwt-token-on-signup-using-flows/64530/1 "2021-06-15T14:37:05Z")

</div>

Whenever a user signs up to our Auth0 infrastructure, I’d like to assign him a unique `mycompany_id` and then include that id in access tokens (added a custom action to the login flow to add the id to the token, which is working fine).

However, it seems like this doesn’t work on signup. If I use a pre-registration flow, request the `mycompany_id` from our API and then set that id as user\_metadata it isn’t saved in the database. If I use a post-registration flow this works fine, however the id is not included in the first access token after the signup process, but only in subsequent logins. Is there a way to achieve this with the Action flows? Or do I need to use Hooks/Rules instead?

---

<div class="post-metadata">

**Author:** ![eosn-fred](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eosn-fred/32/12732_2.png) [@eosn-fred](https://community.auth0.com/u/eosn-fred)\
**Post date:** [June 15, 2021, 2:53pm UTC](https://community.auth0.com/t/is-it-possible-to-assign-a-custom-claim-to-a-jwt-token-on-signup-using-flows/64530/2 "2021-06-15T14:53:00Z")

</div>

This is my Action I’m currently using for testing:

```auto
exports.onExecutePreUserRegistration = async (event, api) => {

  const axios = require('axios')

  axios
    .post('https://mycompanyapi/v1/users', {}, {
      headers: {
        "X-API-KEY": event.secrets.API_KEY
      }
    })
    .then(res => {
      if (res.statusCode == 201) {
        api.user.setUserMetadata("mycopmany_id", res.data.mycopmany_id)
      } else {
        console.error("invalid status code from create user response")
        console.error(res)
        api.access.deny("failed to create mycompany_id", "internal server error")
      }
    })
    .catch(error => {
      console.error("failed to create a new user")
      console.error(error)
      api.access.deny("failed to create mycompany_id", "internal server error")
    })
};

```

---

<div class="post-metadata">

**Author:** ![eosn-fred](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eosn-fred/32/12732_2.png) [@eosn-fred](https://community.auth0.com/u/eosn-fred)\
**Post date:** [June 15, 2021, 3:39pm UTC](https://community.auth0.com/t/is-it-possible-to-assign-a-custom-claim-to-a-jwt-token-on-signup-using-flows/64530/3 "2021-06-15T15:39:00Z")

</div>

Forgot to return the axios call, now it’s working

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 16, 2021, 1:21pm UTC](https://community.auth0.com/t/is-it-possible-to-assign-a-custom-claim-to-a-jwt-token-on-signup-using-flows/64530/4 "2021-06-16T13:21:45Z")

</div>

Perfect! Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 25, 2021, 11:22am UTC](https://community.auth0.com/t/is-it-possible-to-assign-a-custom-claim-to-a-jwt-token-on-signup-using-flows/64530/5 "2021-06-25T11:22:32Z")

</div>


