I am new to MEAN stack. I am using jwt to authenticate api endpoint '/api/candidates'
In client-side/angular js service I have following entry
resumeFactory.get = function(candidateName) {
return $http.get('/api/candidates', {
headers: {
Authorization: 'Bearer '+ authenticationService.getToken()
});
};
on the server-side I have :
app.get('/api/candidates', auth, function (req, res) {
if (!req.payload._id) {
//user not logged in
console.log(req);
res.status(401).json({"message": "no user logged in from candidates"});
}
else {
Candidate.find({}, function (err, candidates) {
if (err) {
res.send(err);
}
res.json(candidates);
});
}
});
This works fine. i.e. 'auth' is able to extract the token from the header
When i change everything to post instead of get :
on client-side
$http.post()
on server side :
app.post()
I get an error from jwt as following:
UnauthorizedError: No authorization token was found
Any suggestions on what is happening?. I can work with get but i want to know why post does not work