I'm building a frontend app with React and Redux and I'm using axios to perform my requests. I would like to get access to all the fields in the header of the response. In my browser I can inspect the header and I can see that all the fields that I need are present(such as token, uid, etc...), but when I call
const request = axios.post(`${ROOT_URL}/auth/sign_in`, props);
request.then((response)=>{
console.log(response.headers);
});
I get just
Object {content-type: "application/json; charset=utf-8", cache-control: "max-age=0, private, must-revalidate"}
Here my browser network tab,as you can see all the other fields are present.
Bests.
In case of CORS requests, browsers can only access the following response headers by default:
If you would like your client app to be able to access other headers, you need to set the Access-Control-Expose-Headers header on the server:
This really helped me, thanks Nick Uraltsev for your answer.
For those of you using nodejs with cors:
In the case you are sending the response in the way of
res.header('Authorization', `Bearer ${token}`).send();
I was facing the same problem. Y did this in my "WebSecurity.java", it's about the setExposedHeaders method in the cors configuration.
I hope it works.