Wednesday, 24 May 2017

Getting a 401 Unauthorized JavaScript

I don't understand why I'm getting a 401 unauthorized response code with this call. My headers in my request are correct and it works if I use a REST Client so it's not the server. I don't know what else it can be, I'm getting back a valid token. Any help would be awesome. Thank You!

auth.upvotePost = function (post) {
    var token = auth.getToken();
    return $http.post('/api/post/' + post + '/upvote', {
        headers: { Authorization: 'Bearer ' + token }
    }).then(function (data) {
        console.log('post Upvoted', data);
    }, function (error) {
        console.log('Error: ', error);
    });
};

For some reason it works on my other service calls like this one below but not for the above code

auth.followUser = function (id, userId) {
    return $http.post('/auth/users/' + id + '/add', userId, {
        headers: { Authorization: 'Bearer ' + auth.getToken() }
    }).then(function (data) {
        console.log('follow successful', data);
    }, function (error) {
        console.log('Error: ', error);
    });
};



via Jhamar S.

No comments:

Post a Comment