Auth0 Home Blog Docs

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

custom-claims

#1

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: https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims#standard-claims

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


#2