Alexey Kopievskiy Alexey Kopievskiy - 3 months ago 12
AngularJS Question

Why response on angular.js do not contain some headers?

First of all, i'll give you img with POSTMAN tests (at the end of this question you'll fild google drive with postman.png)

My problem: there are client on angular.js and laravel api (without access to config and code)

I want build JWT Auth on client
When I send data to api, angular.js send first request - OPTION - (at the end of this question you`ll fild google drive with angular-option.png)

After OPTIONS - POST request (at the end of this question you'll fild google drive with POST-1.png and POST-2.png)
You see, that in response header i have Authorization key with my token, but when I log() request and respone on client, i havenot this header - (at the end of this question you'll fild google drive with response-client.png)

Why in this response there isn't header Authorization?

Link to Google Drive

There is my code

Thanks for help

Answer

Have you registered the interceptor correctly in you module config?

Is so, can you also modify your signin method to see if it is logging the response there? Change the code from

signin: function (data, success, error) {
    $http.post(urls.BASE + '/auth/signin', data).then(function success(response, status, headers){

    })
}

to

signin: function (data, success, error) {
    $http.post(urls.BASE + '/auth/signin', data).then(function success(response)){
        console.log('Status:' + response.status);
        console.log('Response headers');
        console.dir(response.headers());
    })
}

When you use .then for $http.post, the response object contains

The response object has these properties as per angular docs:

data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.