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 user.event.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.
Could you please confirm if you have
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