Post-User Registration

At the Post-User Registration extensibility point, Hooks let you execute custom actions after a new user registers an account and is added to the database. For example, you can send a message to Slack or create a record in your customer relationship management (CRM) system.

Hooks at this extensibility point are non-blocking (asynchronous), which means the Auth0 pipeline will continue to run without waiting for a hook to finish its execution. Thus, the hook's outcome does not affect the Auth0 transaction. Because of this, you should not attempt to modify the user from the hook itself (for example, using a PATCH call).

The Post-User Registration extensibility point is available for database connections. To learn more, see Database Connections.

The triggerId for the Post-User Registration extensibility point is post-user-registration. To learn how to create Hooks for this extensibility point, see Create Hooks.

To learn about other extensibility points, see Extensibility Points.

Starter code and parameters

When creating a Hook executed at the Post-User Registration extensibility point, you may find the following starter code helpful. Parameters that can be passed into and used by the Hook function are listed at the top of the code sample.

/**
@param {object} user - user being created
@param {string} user.id - user's ID (user GUID without "auth0|" database prefix)
@param {string} user.tenant - Auth0 tenant name
@param {string} user.username - user's username
@param {string} user.email - user's email
@param {boolean} user.emailVerified - indicates whether email is verified
@param {string} user.phoneNumber - user's phone number
@param {boolean} user.phoneNumberVerified - indicates whether phone number is verified
@param {object} user.user_metadata - user's user metadata
@param {object} user.app_metadata - user's application metadata
@param {object} context - Auth0 context info, such as connection
@param {string} context.requestLanguage - language of the application agent
@param {object} context.connection - connection info
@param {object} context.connection.id - connection ID
@param {object} context.connection.name - connection name
@param {object} context.connection.tenant - connection tenant
@param {object} context.webtask - Hook (webtask) context
@param {function} cb - function (error, response)
*/

module.exports = function (user, context, cb) {
  // Perform any asynchronous actions, such as send notification to Slack.
  cb();
};

The callback function (cb) at the end of the sample code signals completion and must be included.

Default response

Hooks executed at the Post-User Registration extensibility point ignore any response object.

Starter code response

Once you've customized the starter code, you can test the Hook using the runner embedded in the Hook Editor. The runner simulates a call to the Hook with the appropriate body and response.

Executing the code using the runner requires a save, which means that the original code will be overwritten.

When you run a Hook based on the starter code, the response object is:

{
  "user": {
    "tenant": "my-tenant",
    "username": "user1",
    "email": "user1@foo.com",
    "emailVerified": true,
    "phoneNumber": "1-000-000-0000",
    "phoneNumberVerified": true,
    "user_metadata": {
      "hobby": "surfing"
    },
    "app_metadata": {
      "plan": "full"
    }
  },
  "context": {
    "requestLanguage": "en-us",
    "connection": {
      "id": "con_xxxxxxxxxxxxxxxx",
      "name": "Username-Password-Authentication",
      "tenant": "my-tenant"
    }
  }
}

Sample script: Integrate with Slack

In this example, we use a Hook to have Slack post a new user's username and email address to a specified channel upon user registration.

module.exports = function (user, context, cb) {

  // Read more about incoming webhooks at https://api.slack.com/incoming-webhooks
  var SLACK_HOOK = 'YOUR SLACK HOOK URL';

  // Post the new user's name and email address to the selected channel
  var slack = require('slack-notify')(SLACK_HOOK);
  var message = 'New User: ' + (user.username || user.email) + ' (' + user.email + ')';
  var channel = '#some_channel';

  slack.success({
   text: message,
   channel: channel
  });

  // Return immediately; the request to the Slack API will continue on the sandbox
  cb();
};

Learn more