I am trying to run a POST request to my server url and I have auth0 layer to determine if the user is authenticated. The auth layer only accepts a JWT token and so im trying to add it to the Authorization Bearer Token but it seems like in the tests it gets ignored… Am i doing this correctly?
module.exports = function (user, context, cb) {
const request = require('request');
request({
method: 'POST',
url: ‘path/to/url’,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${context.webtask.token}`
},
body: `some body`
}, function(error, response, body) {
cb(error, response.body);
});
cb();
};
1 Like
Hi @jerryforcode,
Thanks for reaching out to the Auth0 Community!
First, I want to clarify that in the Post Registration Hook, it would not be worth checking if the user is authenticated since:
- If it’s an authenticated user then they cannot be created since they exist, and
- The hook triggers after creating a new user, but before they log in, hence the result will always determine the user as unauthenticated.
Because of that, could you please clarify what you intend to do?
And, could you please clarify your server URL? Is that pointing to any of the Auth0 APIs, or is it another URI?
Looking forward to your reply.
Thank you.
Hi @rueben.tiow,
Thanks for getting back to me.
This will be going to another URI however, I am using this hook to create the user info in my database so I can store it for my records.
I added the auth0 layer for security reasons as it will be inserting records into my database. Unless there is another way to validate that the insertion is coming from auth0 ?
Regards,
Jerry
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!