Rule : Add persistent attributes to the user gives an ERROR when executed

Getting the error : “ERROR: The user does not exist.” when I am trying to execute the default rule “Add persistent attributes to the user”. No changes to the code provided:

function (user, context, callback) {
  user.user_metadata = user.user_metadata || {};
  user.user_metadata.color = user.user_metadata.color || 'blue';
  context.idToken'https://example.com/favorite_color'] = user.user_metadata.color;

  auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
    .then(function(){
        callback(null, user, context);
    })
    .catch(function(err){
        callback(err);
    });
}

What am I doing wrong? I want to add custom claims to the idToken and accessToken. Tried using the example shown here: OpenID Connect Scopes

Code:

const namespace = 'https://myapp.example.com/';
context.idToken[namespace + 'favorite_color'] = user.favorite_color;

but it does not work. I don’t see the claim getting added to the idToken