Hook code not working

Hi,

I’ve written a pre-registration hook that does not seem to be triggering.

The code works fine when using the test runner. It also errors when creating a user via the Auth0 admin console (as expected as it is referencing firstname and lastname attributes that are not passed through the pipeline), but when registering via lock (which captures the additional attributes) it does not seem to trigger, there are no errors or call to the rest endpoint that the code makes.

Any help would be gratefully appreciated!

The code is:

module.exports = function (user, context, cb) {
request = require("request@2.56.0");

var options = {
 method: 'POST',
 url: 'https://emw1-cai.dm-em.informaticacloud.com/active-bpel/public/rt/1WPA8G9Fo8Cgp7iHgzzq8A/CRMCreateContact',
   headers: { 
    'Content-Type': 'application/json'
  }, 
 body: {
      "Email": user.username,
      "FirstName": user.user_metadata.first_name,
      "LastName": user.user_metadata.last_name
 },
 json: true
};

request(options, function (error, callresponse, body) {
 if (error) cb(new Error(error));
 var response = {};
    response.user = {
    user_metadata: {
            first_name: user.user_metadata.first_name,
            last_name: user.user_metadata.last_name,
            crmcontact: body.CRMContactUUID 
      }
    };
    cb(null, response);
});
};

Hi David. Not sure what the error that you are getting is, but you should be able to access a user’s user_metadata from a pre-registration hook. You can try this simpler version (to simplify the code and remove the possibility of the external request failing):

module.exports = function (user, context, cb) {
  
  // this will output the full user object, and you should
  // be able to see its `user_metadata` object populated
  console.log(user);
  
  var response = {};

  response.user = user;

  cb(null, response);
};

You can watch the console.log(user) output by running the Real-time Webtask Logs.

If you are still not seeing the data, you might want to try a cURL post directly to take Lock also out of the picture, with something like this:

curl -X POST \
  https://YOUR_AUTH0_DOMAIN/dbconnections/signup \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"client_id":"A_VALID_CLIENT_ID",
	"email" : "test789@test.com",
	"password":"test",
	"connection":"Username-Password-Authentication",
	"user_metadata":{"name": "john","color": "red"}
}'

One final note, that might be obvious but could be easy to miss: remember to select the hook that you’ll want to use as the “active” one in the dropdown list (you can create multiple hooks but choose only one to run).

1 Like

Hello, I’ve been trying to use pre-registration hook and it’s not working. No logs is being shown in live web task log. Even the simple example is not working. Is there any configurations besides creating the Hook? This is the error:

ExtensibilityLogicError on pre-user-registration: Unauthorized extensibility point.

Below is the code used:

module.exports = function (user, context, cb) {
  console.log('Will make the request');
  var response = {};
  response.user = user;
  
  const request = require('request@2.67.0');
  const options = {
    method: 'post',
    body: {
      user: user,
      context: context
    },
    json: true,
    url: 'https://url/to/signup'
  };
  request(options, function(err, httpResponse, body) {
    cb(err, err ? null : response);
  });
};

The log output is:

12:10:40 AM: Connected
12:10:59 AM: new webtask request
12:10:59 AM: finished webtask request

The console.log output is not shown.

1 Like

Having the same problem with a very simple example.

Registration hooks currently only work with database connections. Is your app configured with a database connection, or another type of login?

Hi @Chipadeedoodah I’m using an app with database connection, and I have the same problem when I run me custom hook in the test console ran successfully, but then the hook not fired when I login into my app.

That definitely shouldn’t be happening, Kevin. If it’s persisting, please contact support.

1 Like

Thanks for reaching out here Chip!

Any update on this?

I’m also getting the same issue. The pre-registration hook I’ve created seems to be working using the runner but whenever I sign-up (passwordless), there is no log of the hook being triggered and the metadata is not shown on the user.

My pre-registration hook code has been copied straight from the sample script:

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

  response.user = {
     user_metadata: { foo: 'bar' },
     app_metadata: { vip: true, score: 7 }
  };

  cb(null, response);
 };

I’m also facing this issue on a tenant that I created 10 days ago. In my other older tenants this hook is working fine. This is a blocking issue in going forward with auth0 integration.

Please update on this issue. Thanks!

I’m also attempting to use the pre-create hook to amend users and block some users from signing up by sending an error for blocked users. The code works in the runner, however it’s not being called at all it seems, when the user is signing up e.g. with Google.

Is this expected behavior and if so, is there an alternative for achieving the desired outcome?

1 Like

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!