Não consigo pegar o token usando a requisição, no console log aparece como NULL.
meu código:
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(private http: HttpClient) { }
login(LoginUsuarioComponent: LoginUsuarioComponent): Observable<Object>{
return this.http.post(API_URL , LoginUsuarioComponent, {observe: 'response'})
.pipe(tap(response => {const authToken = response.headers.get('Authorization');
console.log(authToken);
}));
}
@Component({
selector: 'tb-signin',
templateUrl: './signin.component.html'
})
export class SignInComponent implements OnInit {
@ViewChild('emailInput') userNameInput: ElementRef<HTMLInputElement> | undefined;
loginForm: any;
constructor(private formBuilder:FormBuilder, private authService: AuthService,private PlatformDetectorService: PlatformDetectorService) { }
ngOnInit(){
this.createForm (new LoginUsuarioComponent());
}
createForm(LoginUsuarioComponent: LoginUsuarioComponent){
this.loginForm = this.formBuilder.group({
email: [LoginUsuarioComponent.email, Validators.compose([Validators.required, Validators.email])], // Passando paramentro de obrigatoriedade e desativando o botão submit enquanto o usuário não digitar o e-mail e senha
senha: [LoginUsuarioComponent.senha,Validators.required]
})
}
onSubmit(){
console.log ('Vai se autenticar');
console.log(this.loginForm.value);
if(this.loginForm.valid) {
console.log ('submit');
this.authService.login(this.loginForm.value).subscribe(
success => console.log('sucesso'),
error => console.error(error),
() => console.log ('request completo'))
this.PlatformDetectorService.isPlatformBrowser() && // Usando o focus somente no navegador
this.userNameInput?.nativeElement.focus();
this.loginForm.reset(new LoginUsuarioComponent());