So I have a post like below, I send a POST request to login and the response is empty - which is fine, as expected - but I need to access the 'Authorization' header.
I didn't find any way to access.
const data = {email: "email", password: "password"};
this.http.post(`/login`, data).pipe(
tap(resp => {
console.log(resp); // it will be an empty string
return resp;
})).subscribe((resp: any) => {
console.log(resp.headers.get('Authorization')); // error: Cannot read property 'headers' of null
});
UPDATE Inspired by TheUnreal's answer I added options
this.http.post(`/login`, data, {observe: 'response'} )...
Now I can access some of the headers like 'Cache-Control'.
Probably I need to express the rest of the headers from serverside
Sam Walpole is right in the comment section, most part of the this question was answered on the link he provided - check out.