0

I am currently working with an external API and angular 5. The current issue is when I make a request to the backend with correct credentials I receive a response with an authorization header but angular says that the header does not exist. Here is some small code snipits

return this.http.post<any>(this.apiUrl + "/api/login", farmer,  { observe: 'response' }).pipe(
  map(response => {
    localStorage.setItem("token", response.headers.get('Authorization'))
    return response.headers.get('Authorization');
  })
)

Above is my api service call ^

Below is my component call:

onSubmit() {
if (this.loginForm.valid) {
  this.restApiService.apiLogin(this.loginForm.value).subscribe(response => {
    console.log(response);
    // const keys = response.headers.get('Authorization');
    // console.log("Header Keys", keys)
  });
}

}

From these two snippits I get the output of Null and the token in local storage is null. This could be an overwrite issue but i have also just checked response.headers.get('Authorization'); and it is null. Let me know if i need to post more.

  • 1
    You need to specify the following header in your backend: `Access-Control-Allow-Headers: Authorization` – David Feb 25 '18 at 21:43
  • Possible duplicate of [Angular 2: Get Authorization header](https://stackoverflow.com/questions/42314069/angular-2-get-authorization-header) – Harry Ninh Feb 25 '18 at 22:51

0 Answers0