I'm having authService
that calls my backend endpoint to authenticate and I want to simply return true/false to another component so I can display/hide error message. On top of that, on success I want to store token in localStorage
.
signIn = (signInFormValue) => {
var response = this.authService.authenticate(signInFormValue.username, signInFormValue.password)
if(response) {
console.log(response)
this.invalidCredentials = false;
} else {
this.invalidCredentials = true;
}
}
Which calls this
authenticate(username: string, password: string) {
return this.callAuthenticationEndpoint(username, password).pipe(map(res =>{
localStorage.setItem('token', res.headers.get('Authorization');
return true;
}, err => {return false}))
}
callAuthenticationEndpoint(username: string, password: string): Observable<any> {
var url = this.AUTHENTICATE_URL + 'username=' + username + '&password=' + password;
return this.http.get(url, {observe: "response"});
}
The problem is, response
isn't true/false, but it is