I can’t make the action execute after the user registration (passwordless)

Hey here, i have some troubles creating an action.

I created an action:

// Updates user name on registration (converts user@gmail.com -> user)
exports.onExecutePostUserRegistration = async (event, api) => {
  if (!event.user.email) {
    return;
  }
  const name = event.user.email.split('@')[0];

  const ManagementClient = require('auth0').ManagementClient;
  const management = new ManagementClient({
    domain: event.secrets.AUTH0_DOMAIN,
    clientId: event.secrets.AUTH0_CLIENT_ID,
    clientSecret: event.secrets.AUTH0_CLIENT_SECRET,
  });

  await management.users.update({ id: event.user.user_id }, { name });
};

I clicked Deploy, tested it, and it works—it successfully changes the user’s name.

Then I assigned this action to the Post User Registration trigger and clicked Apply.

After that, I registered a new user on my website, went to the Auth0 console, and checked the user’s name. It still includes @gmail.com, meaning the action did not execute.

What could be the problem?

Hi @vlad5,

Welcome to the Auth0 Community!

I couldn’t find this action in the tenant associated with your email address. Are you using another tenant?

In the tenant logs for this registration, do you see the Actions Executions tab? Does it show that it successfully ran? If it successfully running, I would then recommend using the Real-time Webtask Logs Extension with some console.log() in the action code to further debug this issue.

Let me know!

Thanks,

Mary Beth

Hey @marybeth.hunter , thanks for your reply!

I found a log entry with the type “Failed Post User Registration Hook.”

My action:

// Updates user name on registration (converts user@gmail.com -> user)
exports.onExecutePostUserRegistration = async (event, api) => {
  if (!event.user.email) {
    return;
  }
  const name = event.user.email.split('@')[0];

  const ManagementClient = require('auth0').ManagementClient;
  const management = new ManagementClient({
    domain: event.secrets.AUTH0_DOMAIN,
    clientId: event.secrets.AUTH0_CLIENT_ID,
    clientSecret: event.secrets.AUTH0_CLIENT_SECRET,
  });

  console.log('Trying to update user ', event.user.user_id, ' with name: ', name);
  await management.users.update({ id: event.user.user_id }, { name });
};

The message itself looks like this:

{
  "action_name": "Update user name after registration",
  "response": {
    "error": {
      "message": "The user does not exist.",
      "name": "ManagementApiError",
      "stack": "ManagementApiError: The user does not exist.\n    at UsersManager.parseError (/data/layers/us-west-2.amazonaws.com/_kuGEofdWh_nCW2RPj5wPxDfnOCLzXiSIH9QHw_s7u0=/node_modules/auth0/dist/cjs/management/management-client.js:33:16)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async UsersManager.request (/data/layers/us-west-2.amazonaws.com/_kuGEofdWh_nCW2RPj5wPxDfnOCLzXiSIH9QHw_s7u0=/node_modules/auth0/dist/cjs/lib/runtime.js:119:23)\n    at async UsersManager.update (/data/layers/us-west-2.amazonaws.com/_kuGEofdWh_nCW2RPj5wPxDfnOCLzXiSIH9QHw_s7u0=/node_modules/auth0/dist/cjs/management/__generated/managers/users-manager.js:561:26)\n    at async exports.onExecutePostUserRegistration (/data/io/node22/c15f33fc-d656-4f7b-8dda-5d017d98ed0c/webtask.js:17:3)\n    at async /data/io/a1d82dcbc495089dea716302768d597084946f7c.js:3:842"
    },
    "logs": "Trying to update user  email|xyz  with name:  xyz_usr\n",
    "stats": {
      "action_duration_ms": 401
    }
  },
  "started_at": "2025-01-27T05:13:53.861Z",
  "ended_at": "2025-01-27T05:13:54.269969339Z"
}

If I go to the action, press the “Test” button, and set event.user.user_id to “email|xyz” (the same value as in the log), the action executes successfully. When I navigate to this user in the Auth0 console, the user’s name is updated (e.g., “j+smith”).

However, according to the logs, at the time this action executes, the user cannot be found. Could there be any nuances in how the Post User Registration hook works?

Hi @vlad5,

Please see this article: Update Made in Post-User Registration Action Not Available in Post-Login Action

We recommend using a post-login action to perform updates to the user during an authentication transaction.

Can you try adding this login to a post-login action and see if it executes as expected?

Thanks,

Mary Beth

I added a post-login action that checks for the presence of a field in app_metadata and adds a custom claim to the ID token. The rest of the logic I moved to my Node.js application.

1 Like

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