How do I get a Header for a response with Angular 2+? In my case, I'm using version 6.
I would like to get this authorization data to be stored in the Browser's LocalSession.
I am using the following method to perform the request:
public login(email: string, password: string): Observable<User> {
return this.http.post<User>(this.url, { username: email, password: password })
.do(user => {
this.user = user;
});
}
In my component class, try to redeem through the HttpHeaderResponse Method, but without success!
public login(): void {
this.signinService.login(this.loginForm.value.email, this.loginForm.value.password
).subscribe(
(user: User) => {
this.notificationService.notify('Usuário logado com sucesso');
let header: HttpHeaderResponse = new HttpHeaderResponse();
console.log(header);
localStorage.setItem('token', 'Aqui vai o Token');
},
(response: HttpErrorResponse) => this.notificationService.notify(response.error.message),
() => {
this.router.navigate([atob(this.navigateTo)]);
});
}
Thank you for the collaboration of the community!