User Metadata is Not Correctly Updated from a Rule
Last Updated:
Overview
There are no errors after login execution, but the metadata is empty.
Applies To
- User Metadata
- Rules
- app_metadata
Cause
Data is not persisting if you don't resolve the Promise.
Troubleshooting
Check when and how the rules are trying to update metadata.
Solution
Rules using the function updateUserMetadata() triggers an asynchronous call that needs to be resolved. You'll be expecting no errors since this function will end with a pending Promise. Here are a few examples in our documentation:
https://auth0.com/docs/manage-users/user-accounts/metadata/manage-metadata-rules#update-metadata
As you can see in this snippet, it's needed to handle the Promise with "then" and "catch" to persist the data:
function(user, context, callback){
...
auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
.then(function(){
callback(null, user, context);
})
.catch(function(err){
callback(err);
});
}