I’m trying to do an HTTP call from Auth0 to my REST endpoint to save user in my db in pre-registration hook. However, it’s giving an 500 error which I am not able to understand:
request = require("request");
var options = {
method: 'POST',
url: 'http://domainname.com/users/create',
headers: { 'Content-Type': 'application/json' },
body: {
"username": user.email,
"password": user.password ,
"api_account_id":user.user_metadata'api_account_id'],
"organization":user.user_metadata'organization']
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
The information provided is not sufficient to provide a definitive answer (for example, you did not include full details about the error). However, based on the code provided and the fact that a pre-registration hook expects the following logic:
module.exports = function (user, context, cb) {
var response = {};
// ... logic here to calculate response
cb(null, response);
};
There is at least one problematic situation with the code you showed; you’re not calling the callback cb
function to signal that your logic has completed.
In particular, it should be something like (notice the call to cb
both for error situations and successful completion of the hook’s logic):
// ...
request(options, function (error, response, body) {
if (error) cb(new Error(error));
console.log(body);
cb(null, response); // assuming there's a response variable
});
Actually i wanted to know , how can i call my rest api end point in preregistration hook in auth 0.
Actually i wanted to know , how can i call my rest api end point in preregistration hook in auth 0.
You can call it like in the sample code I included in the answer. The key point is that you need to call the hook callback in any code path possible after receiving the response.