Rule to add user_metadata attributes to user object in Authentication API not showing up

Modified the Add persistent attributes to the user rule to add phone_number attribute under user_metadata object to user object but user object received in React app does not include phone_number attribute even though it shows in the console log when debugging rule.

Here is the rule code:

function addPersistenceAttribute(user, context, callback) {
  user.user_metadata = user.user_metadata || {};
  user.user_metadata.phone_number = user.user_metadata.phone_number || '12345678';
  context.idToken.phone_number = user.user_metadata.phone_number;

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

Hi @m.kuo5

What do you mean “user object”? Do you mean the ID token or something else?

John

Hi John,

Yeah the idToken or the user object through useAuth0 through the auth0-react package.

Can you capture the ID token and use JWT.io to verify the contents? What does it show?

John

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon, I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!