Pre registration hook set non-metadata user info?

@dan.woda So just to follow up, was it validated as a bug? And if it was, should I account on a planned fix?

We haven’t heard back on this front just yet. As soon as we hear something we will be sure to share :+1:

1 Like

Thank you :slight_smile:

1 Like

@dan.woda @James.Morrison

We still don’t have a solution for the actual topic on this thread; that is, how to set non metadata user info from the pre-registration hook.

I’m using a regular db (not passwordless), and from the hook I can store user_metadata or app_metadata, but none of the root attributes, such as given_name or nickname. Is this possible?

Btw, I disabled all other rules, hooks, and anything else that might have interfered with this hook, and it still doesn’t work. I’ve also sent our tenant name in a PM as requested.

1 Like

Hi all,

I’m probably just repeating stuff that is already known so apologies in advance: The following hook appears to work when testing the hook, but isn’t working when a user actually registers.

module.exports = function (user, context, cb) {
  var response = {};

  response.user = user;

  // Add user or app metadata to the newly created user
  // response.user.user_metadata = { foo: 'bar' };
  // response.user.app_metadata = { vip: true, score: 7 };
  response.user.given_name = "Foo";
  response.user.family_name = "Bar";
  response.user.user_metadata = { gname: "Foo", fname: "Bar" };

  cb(null, response);
};

Resulting user profile:

{
    "created_at": "2020-02-12T16:40:25.598Z",
    "email": "garrus@sr2.ca",
    "email_verified": false,
    "identities": [
        {
            "connection": "Username-Password-Authentication",
            "provider": "auth0",
            "user_id": "5e442a79ba16fb0e68e8e488",
            "isSocial": false
        }
    ],
    "name": "garrus@sr2.ca",
    "nickname": "garrus",
    "picture": "https://s.gravatar.com/avatar/df1e6608b8db441fc3c4aedd078d2956?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fga.png",
    "updated_at": "2020-02-12T16:40:25.598Z",
    "user_id": "auth0|5e442a79ba16fb0e68e8e488",
    "user_metadata": {
        "gname": "Foo",
        "fname": "Bar"
    },
    "last_ip": "198.84.135.136",
    "last_login": "2020-02-12T16:40:25.575Z",
    "logins_count": 1,
    "blocked_for": [],
    "guardian_authenticators": []
}

Webtask logs:

11:59:45 AM:
 PROFILE IN:
{ id: 'abc123',
tenant: 'my-tenant',
username: 'user1',
password: 'xxxxxxx',
email: 'user1@foo.com',
emailVerified: false,
phoneNumber: '1-000-000-0000',
phoneNumberVerified: false,
user_metadata: { hobby: 'surfing' },
app_metadata: { plan: 'full' } }

PROFILE OUT:
{ id: 'abc123',
tenant: 'my-tenant',
username: 'user1',
password: 'xxxxxxx',
email: 'user1@foo.com',
emailVerified: false,
phoneNumber: '1-000-000-0000',
phoneNumberVerified: false,
user_metadata: { gname: 'Foo', fname: 'Bar' },
app_metadata: { plan: 'full' },
given_name: 'Foo',
family_name: 'Bar' }
1 Like

@aneacsu_c
Maybe you can use a rule to save your metadata into your id_token.
You cannot change all fields but it is easy to add new fields with unique namespace and then use them in your app.
Rule example:

function (user, context, callback) {
   if (context.idToken && user.user_metadata) {
     const namespace = 'https://crm.kb.com/';
     context.idToken[namespace + 'name'] = user.user_metadata.name;
   }

   callback(null, user, context);
} 
2 Likes

I think you should update this page Pre-User Registration, that for passwordless connection, persisting the data currently doesnt work

1 Like

@markd
on this page it says that:

If you specify  `app_metadata`  and  `user_metadata`  in the response object, Auth0 adds this information to the new user. 

So im not sure you can persist other fields then metadatas

1 Like

@guy1812 agreed, I’m pretty sure you can’t use this for root attributes.

@aneacsu_c, @krilbe: bit of an ugly workaround but you could save your desired attributes in metadata in the hook, then have a rule that updates the root attributes with the values stored in metadata. And be sure to submit a feature request to have the pre-reg hook support setting root attributes.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.