Read Metadata

You can read metadata using rules with the Management API and with Lock. You can also search for profile-related information in user_metadata, such as:

  • name
  • nickname
  • given_name
  • family_name

Beginning 1 September 2017, new tenants cannot search any of the app_metadata fields. Only tenants associated with paid subscriptions that were created on/before 31 August 2017 can search the app_metadata fields.

As an example, assume the following metadata is stored for a user with the email address jane.doe@example.com:

{
    "emails": "jane.doe@example.com",
    "user_metadata": {
        "hobby": "surfing"
    },
    "app_metadata": {
        "plan": "full"
    }
}

Read metadata with the Management API

Using the example metadata above, you can refer to specific items from the dataset in Rules or via a call to the Management API as follows:

console.log(user.email); // "jane.doe@example.com"
console.log(user.user_metadata.hobby); // "surfing"
console.log(user.app_metadata.plan); // "full"

Any valid JSON snippet can be used as metadata.

In Management APIv1, all metadata is stored in the metadata field. Data stored in this field is now available from the Management APIv2 as app_metadata.

Read metadata with Lock

Using the Lock library, you can read the user's user_metadata properties the same way you would read any other user profile property. This example retrieves the value associated with user_metadata.hobby using the example user metadata listed above:

lock.getUserInfo(accessToken, function(error, profile) {
  if (!error) {
    document.getElementById('hobby').textContent = profile.user_metadata.hobby;
  }
});

For details on how to initialize lock refer to Auth0Lock(clientID, domain, options).

Keep Reading