I am making a call to my Web API to login. The call returns a single JSON object with a single property called token.
In my AuthService I have the following function:
login(model: any) {
return this.http.post('http://localhost:5000/api/auth.login', model, httpOptions).pipe(map((response: Response) => {
console.log(response);
if (response) {
// localStorage.setItem('token', jwtHelper.decodeToken(response.token));
// this.decodedToken = jwtHelper.decodeToken(response.token);
// this.userToken = response.token;
}
}));
}
Here is what the console.log of response looks like:
{token: "eyJhbGciOiJIUzXxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiO…CDNojrJEwmuIbLOjhCxzDwls22SA4Whpklh7zPFaR6g_1iQcQ"}
I could make this function return nothing to the component calling it, but in order to set the token in local storage and a few other properties, I am using pipe and then map. Is this correct? response.token is throwing an error everywhere I try to access it because typescript doesn't know about the token property on the response.