Post User Registration user does not have user.name property

Hello,

I’ve written a Post-User Registration Action to create a user in a 3rd party application (Hubspot) once the user has been created in the Auth0 database. I need to port over the email and name fields to this application every time a new user has signed up.

My action successfully gets called when my application does a post to create the user in auth0 however, when I log the incoming data on the event.user, I see something like this in the Action Logs despite providing the name field:

{
  email: 'email@emailProvider.com',
  tenant: 'someTenant',
  user_id: 'auth0|fooBar',
  app_metadata: {
    companyId: 'someCompany',
    customMetaField: {
      flagOne: false,
      flagTwo: false,
    }
  },
  user_metadata: {},
  created_at: undefined,
  updated_at: undefined,
  email_verified: true,
  phone_verified: false
}

There is no name field, and other fields like the created_at and updated_at are undefined.
However when I look at the user details in auth0, it has the name. The raw JSON shows all the fields including the created_at and updated_at fields.

When I use the action tester, that request has all the user information specified and my action works perfectly if I receive all the provided data, but somehow I’m not getting all that information in reality.

Does anyone have an idea why this data isn’t coming through? I appreciate any help on this issue.

Thank you,

Giles

Hi @gilesf,

Welcome to the Auth0 Community!

The correct property to call for the user’s name in a Post User Registration Action is the event.user.name property,

See the Actions Triggers: post-user-registration - Event Object documentation for the full list of callable properties.

Please let me know if you have any questions.

Thanks,
Rueben

Thanks for your response @rueben.tiow

I’m not sure I understand your answer based on the documentation you’ve linked to. According to the event object documentation, the user is a property under the event and it has the name directly on it.

I’m currently doing something like this in my action:

exports.onExecutePostUserRegistration = async (event, api) => {
  const request = require('request');

  console.log(event.user)
  console.log(`name`, event.user.name)

  const firstName = event.user.name ? event.user.name.split(' ')[0] : ''
  const lastName = event.user.name ? event.user.name.split(' ')[1] : ''

My printouts show me that the user exists but it just doesn’t have the name. Where does the user come from in your example? Would you be able to show me an example?

Thanks for your help,
Giles

Hi @gilesf,

Thank you for your response.

I appreciate you sharing your Action script with me. After testing it on my side, I could not reproduce the issue you encountered. The code snippet you provided worked perfectly and successfully set the user’s firstName and lastName variables.

To support my statement, I have included a screenshot below displaying the results of my tests:

In this case, I would like to kindly suggest using the Real-time Webtask Logs Extension, which allows you to monitor the console.log() statements in real-time when a user signs up.

I suspect the issue you are facing might be due to the absence of a name attribute for the created user.

To assist you further, could you please provide clarity on how this user is being created?

Are they signing up through your app’s login page, or are you creating them on their behalf using the Management API’s Create a user endpoint?

I look forward to your update.

Thanks,
Rueben

Hi @rueben.tiow,

Thanks for your response. I actually also ran the same test using the action tester and came to the same conclusion that nothing was wrong with the action itself. The problem is indeed that I’m not getting the name on the incoming event.user object and so, I believe the problem is upstream from the action.

To answer your question, we use the management client to create the user and then request a password change. The code looks something like this (modified slightly to omit sensitive information):

public createUser = ({ userId, email, fullName, appMetadata}): Promise<void> => {
    await this.managementClient.createUser({
      email,
      name: fullName,  // <---
      user_id: userId,
      password: 'password',
      connection: 'Username-Password-Authentication',
      verify_email: false,
      email_verified: true,
      app_metadata: appMetadata
    });

    await this.authenticationClient.requestChangePasswordEmail({
      email,
      connection: 'Username-Password-Authentication'
    });
}

As you can see, we do populate the name field when the user is created. I know that it works given that the name is present when I view the user in auth0 (User Management > Users) and it is present in the raw JSON details. The app_metadata fields are also what I expect them to be in the created user details.

The Action > Action Logs feature that you have in beta shows me my logs as I execute the above code. I’m able to run that snippet manually, and I see that I do not have the name field or the metadata as I explained in my previous post. I therefore believe that either the action isn’t getting all the info being sent to the management API or that something in-between that I’m unaware of may be removing this or prevent this info from getting to the action.

Does the Real-time Webtask Logs Extension work differently or provide me with some other benefit? As far as I can tell, I get the same result but maybe I’m not using it properly.

Best regards,
Giles

Hi @gilesf,

Thank you for your detailed reply.

The Realtime Webtask Logs Extension works similarly to the Action’s Debugger interface, but in this case, it will show all the logs pertaining to the login transaction.

Now, looking at your code snippet carefully, it looks like you are passing the userID, email, fullName, and appMetadata to your createUser function to set those values appropriately to the user’s profile.

Could you please confirm the behavior you observe when passing hardcoded values?

Doing so will help us narrow down whether the values passed in the function are the correct and expected values.

Thanks,
Rueben

Hi @rueben.tiow,

I made a POST to /api/v2/users from the auth0 documentation page with the following hard coded request body:

{
  "email": "john.doe@gmail.com",
  "email_verified": true,
  "app_metadata": {
   "foo": "bar"
  },
  "name": "John Doe",
  "user_id": "abc",
  "connection": "Username-Password-Authentication",
  "password": "secret123$5",
  "verify_email": false
}

and I received a 201 response:

{
  "created_at": "2023-06-13T22:07:38.834Z",
  "email": "john.doe@gmail.com",
  "email_verified": true,
  "identities": [
    {
      "user_id": "abc",
      "connection": "Username-Password-Authentication",
      "provider": "auth0",
      "isSocial": false
    }
  ],
  "name": "John Doe",
  "nickname": "john.doe",
  "updated_at": "2023-06-13T22:07:38.835Z",
  "user_id": "auth0|abc",
  "app_metadata": {
    "foo": "bar"
  }
}

The action logs show me this:

{
  email: 'john.doe@gmail.com',
  tenant: 'XYZ',
  user_id: 'auth0|abc',
  app_metadata: { foo: 'bar' },
  user_metadata: {},
  created_at: undefined,
  updated_at: undefined,
  email_verified: true,
  phone_verified: false
}

The Real-time Webtask logs did not show me any logs. I occasionally get a " finished webtask request" which seems unrelated. Perhaps I’m doing something wrong here? The documentation for the real-time webtask log references rules but not actions:

Any thoughts on this? I tried to remove my code/application from my test, and so this is just a direct post right to auth0. I seem to be getting the same result - which is perplexing.

Thanks you your help,

Giles

Hi @gilesf,

Thank you for your reply.

In your 201 response, I noticed that you successfully created the user with the name property.

With the Action script, you should see the name John Doe produced in the logs.

If this was not the case, could you please confirm if you creating the user with the Realtime Webtask logs extension already opened?

Alternatively, using the Test feature in the Auth0 Debugger shows that the Action script works correctly.

Could you please confirm if you see the same behavior?

Thanks,
Rueben

Hi @rueben.tiow,

Yes, the user definitely has the name property in auth0 when created this way.

If this was not the case, could you please confirm if you creating the user with the Realtime Webtask logs extension already opened?

Yes, I open the Real-time Webtask Logs first and then run the request. In the following image, you can see I opened the logger at 12:39pm and I ran the request at 12:48pm:

When I do the same thing with the Actions Logs, I see this:

Alternatively, using the Test feature in the Auth0 Debugger shows that the Action script works correctly.

I tested my Action using the action tester before opening up this issue and it was working there. From my original post:

When I use the action tester, that request has all the user information specified and my action works perfectly if I receive all the provided data, but somehow I’m not getting all that information in reality.

This is what is confusing me. It seems like the management API and action are working independently, but when used together, it doesn’t work. I’ve deduced that some processing must be happening in-between the two that makes it so that not all the data gets to the action. I have no clue where that may be happening because I don’t have any other hooks set up. I do have a rule that adds some information to the token, but that shouldn’t affect this either.

Giles

Hi, just jumping in here to say that I’m experiencing the exact same issue as @gilesf and wondering if there is a solution other than building the full name from concating family and given names.

1 Like

Hi @patrick14,

I was never able to resolve this issue. Are you saying that you can see the given_name and family_name properties on the event.user object? In my case, none of the properties aside from the email are what they are shown to be in the auth0 interface. I still do not know why those properties on not present in the post-registration hook.

My use case: when a user is registered in Auth0, depending on a field in their app_metadata, I make an API call to Databricks to provision a user. The created used in Databricks kept getting their email as their name. This is how I encountered the issue.

Despite having

name: Foo Bar

in their user_metadata after user creation, the event in the hook never had the value. It did have familyName and givenName so I just used that.

To solve, I post to Databricks using

    "name" : {
      "familyName": familyName,
      "givenName": givenName
    }

but I couldn’t figure out why name wasn’t in the event object.

Hi @gilesf,

It’s quite interesting that the name property seems to be missing.

In my tests, I was able to create a new Action script, include the console.log(event.user), and print the results:

From my results, I managed to match the name property that was passed with the name in the results.

Based on your screenshot, it appears that the event.user object didn’t receive any values for the name. I conducted an additional test by not providing a value for the name property, and I can confirm that this produces the same result you observed. Specifically, the name property holds no value:

Would you be able to try creating a new script and just printing the event.user object?

Let me also mention that the Management API and Actions test debugger interface are independent of each other.

If you need to debug further, I recommend using the Real-time Webtask Logs Extension.

Thanks,
Rueben

Here is the behavior that I am seeing. I create a user with the following request:

  "request": {
    "url": "https://omitted.us.auth0.com/api/v2/users",
    "method": "POST",
    "body": "{\"email\":\"auth0-test@omitted.com\",\"email_verified\":true,\"connection\":\"Username-Password-Authentication\",\"verify_email\":false,\"app_metadata\":{\"applications\":{\"omitted\":[\"omitted\"]}},\"password\":\"omitted\",\"given_name\":\"Auth0\",\"family_name\":\"Test\",\"name\":\"Auth0 Test\"}",
    "headers": {
      "Content-Type": "application/json",
      "User-Agent": "Retool/2.0 (+https://docs.tryretool.com/docs/apis)",
      "Accept": "application/json",
      "Authorization": "---sanitized---",
    }

Note that there is \"name\":\"Auth0 Test\", and we get a response of:

  "response": {
    "data": {
      "created_at": "2023-08-25T16:13:07.297Z",
      "email": "auth0-test@omitted.com",
      "email_verified": true,
      "family_name": "Test",
      "given_name": "Auth0",
      "identities": [omitted],
      "name": "Auth0 Test",

so I know that Auth0 has the name somewhere.

Now, lets look at Action execution logs. The first line of my action is:

exports.onExecutePostUserRegistration = async (event, api) => {
  console.log(`PostUserRegistration for user: ${JSON.stringify(event.user)}`)

and the log for this post-user-registration event is this:

PostUserRegistration for user: 
{
  "email": "auth0-test@omitted.com",
  "family_name": "Test",
  "given_name": "Auth0",
  "tenant": "omitted",
  "user_id": "auth0|64e8d313843778258e757bc4",
  "app_metadata": {
    "applications": {
      "omitted": [
        "omitted"
      ]
    }
  },
  "user_metadata": {},
  "email_verified": true,
  "phone_verified": false
}

See here that name is not present.

Hi @patrick14,

Thanks for the update.

Could you please send me the name of your tenant and the user_id as a direct message to look into this?

Thanks,
Rueben

Hi there, I’m having the exact same issue with the post user registration action. I am using the API to create a Passwordless user, which works fine and the “name” field shows up fine in Auth0 and the API response, but the actual object I get from event.user does not have a name property. This really must be a bug in the Auth0 workflow. Can someone help here? I also do not have a given name or family name in my workflow so can’t use that workaround. Any help appreciated!

Hello. Any updates on this issue? Getting the same in a post signup action. No name, picture, creation date. But when getting to a client app, idToken has all this info.

Hi @matt27 and @bdimonik,

It looks like the Post-User Registration Action is not printing the user’s name property regardless of creating a user with a name.

I have submitted this issue as a bug to our engineering teams and am waiting for a response. I’ll keep everybody posted on the updates.

Thanks,
Rueben

2 Likes

Hi everybody,

I have an update! After checking with our Engineering team, I was informed that the Post-User Registration does not contain the user.name property by design, despite what is stated in our documentation. I will follow up with our doc’s team to address this inconsistency.

As a workaround, you can query this information using the Management API in the Action to call the Get a User endpoint.

Please refer to the documentation below:

Cheers!
Rueben

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