I found this code online and can't seem to understand its purpose. Why is the .map
method called twice, are the res
variable the same in both method?
login(email, password) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http
.post(
'/login',
JSON.stringify({ email, password }),
{ headers }
)
.map(res => res.json())
.map((res) => {
if (res.success) {
localStorage.setItem('auth_token', res.auth_token);
this.loggedIn = true;
}
return res.success;
});
}