User metadata is not correctly updated from a Rule

Problem statement

There are no errors after login execution, but the metadata is empty

Cause

  • Data is not persisting if you don’t resolve the Promise

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:

As you can see in the code snippet below, 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);
    });
}