# Adding new keys to the user object

**URL:** <https://community.auth0.com/t/adding-new-keys-to-the-user-object/61100>\
**Category:** Get Help\
**Created:** [April 14, 2021, 3:43pm UTC](https://community.auth0.com/t/adding-new-keys-to-the-user-object/61100 "2021-04-14T15:43:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ac98](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ac98/32/28794_2.png) [@ac98](https://community.auth0.com/u/ac98)\
**Post date:** [April 14, 2021, 3:43pm UTC](https://community.auth0.com/t/adding-new-keys-to-the-user-object/61100/1 "2021-04-14T15:43:58Z")

</div>

Is there any way we can add a custom field to the user object once a user signs up and gets authenticated? For instance, I’d like to store a StripeID key-value pair in the auth0 object. Thanks!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 14, 2021, 6:57pm UTC](https://community.auth0.com/t/adding-new-keys-to-the-user-object/61100/3 "2021-04-14T18:57:07Z")

</div>

Hi @ac98,

Welcome to the Community!

For adding things such as external IDs related to a user, you can use metadata on the user object. There are two types of metadata associated with a user: app metadata and user metadata. App metadata is application-specific (e.g. storing a flag that indicates to the app that the user has paid for something sold within the app). User metadata is for things like contact preferences or other data that is true across multiple apps.

You can read more about metadata here:

> **[Understand How Metadata Works in User Profiles](https://auth0.com/docs/manage-users/user-accounts/metadata)**
>
> Describes Auth0 user, application, and client metadata. Learn how you can use metadata to store information that does not originate from an identity provider.

For your use case, it sounds like app metadata might be preferred. You can add metadata in a [rule](https://auth0.com/docs/rules):

```auto
function(user, context, callback){
  user.user_metadata = user.app_metadata || {};
  // update the app_metadata that will be part of the response
  user.app_metadata.stripeID = 'abc123';

  // persist the app_metadata update
  auth0.users.updateUserMetadata(user.user_id, user.app_metadata)
    .then(function(){
      callback(null, user, context);
    })
    .catch(function(err){
      callback(err);
    });
}

```

---

<div class="post-metadata">

**Author:** ![ac98](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ac98/32/28794_2.png) [@ac98](https://community.auth0.com/u/ac98)\
**Post date:** [April 15, 2021, 8:00am UTC](https://community.auth0.com/t/adding-new-keys-to-the-user-object/61100/6 "2021-04-15T08:00:55Z")

</div>

For some reason, when I console.log(user), I do not see the field user\_metadata even though the user\_metadata field is filled in when I look at a particular user in User Management \> Users. Is there any way that I can choose which attributes/keys get returned when I access the user object because it seems like I’m currently only getting a subset? I only see email, email\_verified, name, nickname, picture, sub, and updated\_at as accessible keys/attributes when I print a user object on the front-end, but would also like user\_metadata

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 15, 2021, 11:17am UTC](https://community.auth0.com/t/adding-new-keys-to-the-user-object/61100/7 "2021-04-15T11:17:24Z")

</div>

It sounds like you need to add the user metadata to the ID Token so that your frontend app can read it:

```auto
function(user, context, callback){
  user.user_metadata = user.app_metadata || {};
  // update the app_metadata that will be part of the response
  user.app_metadata.stripeID = 'abc123';

  const namespace = 'https://YOUR_APP_URL';
  context.idToken[namespace + '/app_metadata'] = user.app_metadata;

  // persist the app_metadata update
  auth0.users.updateUserMetadata(user.user_id, user.app_metadata)
    .then(function(){
      callback(null, user, context);
    })
    .catch(function(err){
      callback(err);
    });
}

```

Be sure to update the namespace to your own URL. A namespace is required for custom claims so that the claim does not collide with others.

---

<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 30, 2021, 11:17am UTC](https://community.auth0.com/t/adding-new-keys-to-the-user-object/61100/8 "2021-04-30T11:17:37Z")

</div>

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