Learn how to manage with app metadata, user metadata, and client metadata using Rules.
The End of Life (EOL) date of Rules and Hooks will be November 18, 2026, and they are no longer available to new tenants created as of October 16, 2023. Existing tenants with active Hooks will retain Hooks product access through end of life.We highly recommend that you use Actions to extend Auth0. With Actions, you have access to rich type information, inline documentation, and public npm packages, and can connect external integrations that enhance your overall extensibility experience. To learn more about what Actions offer, read Understand How Auth0 Actions Work.To help with your migration, we offer guides that will help you migrate from Rules to Actions and migrate from Hooks to Actions. We also have a dedicated Move to Actions page that highlights feature comparisons, an Actions demo, and other resources to help you on your migration journey.To read more about the Rules and Hooks deprecation, read our blog post: Preparing for Rules and Hooks End of Life.
You can read, update, and delete metadata using Auth0 Rules. In the following sections, we will refer to this example where the user and their information is represented by the following JSON snippet:
You can read metadata using rules with the . You can also search for profile-related information in user_metadata, such as:
name
nickname
given_name
family_name
By default, user profile attributes provided by other than Auth0 (such as Google, Facebook, or X) are not directly editable because they are updated from the identity provider each time the user logs in. Fore more information on attributes from identity providers, read Configure Identity Provider Connection for User Profile Updates.To be able to edit the name, nickname, given_name, family_name, or picture root attributes on the normalized user profile, you must configure your connection sync with Auth0 so that user attributes will be updated from the identity provider only on user profile creation. These root attributes will then be available to be edited individually or by bulk importsAs an example, assume the following metadata is stored for a user with the email address jane.doe@example.com:
Any valid JSON snippet can be used as metadata, but note that user.app_metadata is Undefined by default.To read the available metadata, you will need to access the correct user property.
Application metadata (clientMetadata) is an optional, top-level property of the context object. Existing applications will have no value for this property.
Copy
Ask AI
function(user, context, callback){ context.clientMetadata = context.clientMetadata || {}; if (context.clientMetadata.usersuppliedkey1 === 'black'){ // this code would not be executed for the user } ...}
function(user, context, callback){ user.app_metadata = user.app_metadata || {}; // update the app_metadata that will be part of the response user.app_metadata.roles = user.app_metadata.roles || []; user.app_metadata.roles.push('administrator'); // persist the app_metadata update auth0.users.updateAppMetadata(user.user_id, user.app_metadata) .then(function(){ callback(null, user, context); }) .catch(function(err){ callback(err); });}
This results in the following JSON representation of the user profile details:
To reduce the rule’s processing time, you may update both the app_metadata and user_metadata in the same rule:
Copy
Ask AI
function(user, context, callback){ var q = require('q'); user.app_metadata = user.app_metadata || {}; user.user_metadata = user.user_metadata || {}; // update the user_metadata that will be part of the response user.user_metadata.preferences = user.user_metadata.preferences || {}; user.user_metadata.preferences.fontSize = 12; // update the app_metadata that will be part of the response user.app_metadata.roles = user.app_metadata.roles || []; user.app_metadata.roles.push('admin'); // persist the app_metadata update var appMetadataPromise = auth0.users.updateAppMetadata(user.user_id, user.app_metadata); // persist the user_metadata update var userMetadataPromise = auth0.users.updateUserMetadata(user.user_id, user.user_metadata); // using q library to wait for all promises to complete q.all([userMetadataPromise, appMetadataPromise]) .then(function(){ callback(null, user, context); }) .catch(function(err){ callback(err); });}
This results in the following JSON representation of the user profile details:
To delete the user’s roles, use the following sample rule:
Copy
Ask AI
function(user, context, callback){ user.app_metadata = user.app_metadata || {}; // update the app_metadata that will be part of the response user.app_metadata.roles = null; // persist the app_metadata update auth0.users.updateAppMetadata(user.user_id, user.app_metadata) .then(function(){ callback(null, user, context); }) .catch(function(err){ callback(err); });}
This results in the following JSON representation of the user profile:
To delete a single value of a property, remove that specific value. For example, to remove the writer role from the user profile:
Copy
Ask AI
function(user, context, callback){ user.app_metadata = user.app_metadata || {}; user.app_metadata.roles = user.app_metadata.roles || []; var index = user.app_metadata.roles.indexOf('writer'); if (index !== -1){ // update the app_metadata that will be part of the response user.app_metadata.roles.splice(index, 1); } // persist the app_metadata update auth0.users.updateAppMetadata(user.user_id, user.app_metadata) .then(function(){ callback(null, user, context); }) .catch(function(err){ callback(err); });}
This results in the following JSON representation of the user profile: