Reputation: 59
I am working on a signup page and I am lost trying to set the Authorization Bearer Header. I am using jsonwebtokens to generate the token. I know how to set the header on postman, but how do I set it for the actual route I’m signing up to and be able to use it in my auth middleware for other endpoints ? As postman is just for tests
Upvotes: 2
Views: 15324
Reputation: 121
request.setHeader('Authorization', 'Bearer '+accessToken)
Upvotes: 3
Reputation: 1995
you can set headers inside request in your route. Using request
module.
app.post('/test', (req, res, next) => {
console.log("inside the test");
request.post({
url: api_address,
body: JSON.stringify(send),
headers: {
"Content-Type":"application/json",
"Authorization": "Bearer 71D50F9987529"
}
}, function (error, response, body) {
console.log("hiii");
console.log(response.statusCode);
if (!error && response.statusCode == 200) {
// Successful call
var results = JSON.parse(body);
console.log(results) // View Results
}
});
});
Upvotes: 2