Add name to signup form

Hi @somekh.dave,

AFAIK you will not be able to update the root attributes on signup using lock.

You can however, use the metadata to set the name attribute in a rule.

Check that the metadata and the attribute don’t match, and then make a call to the management API to change the root attribute.

Something like this:

function (user, context, callback) {

  if (!user.app_metadata.name === user.name) {
    var ManagementClient = require('auth0@2.19').ManagementClient;
    var management = new ManagementClient({
      token: auth0.accessToken,
      domain: auth0.domain
    });

    var params = { id: user.user_id };
    var data = { name : user.app_metadata.name };

    management.users.update(params, data, function (err, users) {
      if (err) {
        //handle err
      }
      console.log(user);
      callback(null, user, context);
    });
  };

  callback(null, user, context);
};

I haven’t tested this, but it should get you most of the way there.

Hope this helps!
Dan

2 Likes