Post-user-registration hook Error: Request failed with status code 401

Hi there! So I’m trying to implement the following post-user-registration hook:

module.exports = function(user, context, cb) {
  var axios = require('axios');
    axios
      .post(
        'https://bb89cc037d18.ngrok.io/interview/post', {email: user.email})
      .then(res => console.log(res))
      .catch(err => console.log(err));
    cb();
};

My backend has Auth0 implemented and also checkJwt middleware for each endpoint. When I run the script above, the response in the logs is the following:

Error: Request failed with status code 401

And a very long detail after that. I just don’t understand why it’s a 401, given that the Hook testing shell in Auth0 platform automatically assigns a Bearer ACCESS_TOKEN to avoid 401 error. I tried sending headers authorization token straight in the hook axios options argument but of course, that overlaps with the authorization header that auth0 sets by default in the hook headers testing IDE. I also tried replacing that default authorization header with my ACCESS_TOKEN provided by Auth0 through the cURL method but that would give me a 500 error.

I have no clue about why my backend is rejecting the request by sending a 401, when the request is carrying the corresponding Bearer ACCESS_TOKEN.

Any ideas?

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!