Hi I am trying to do something with the result of a http request but my callback is never being executed and I can't wrap my head around why..
I've followed the example from here on this part..
This is my code:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as moment from "moment";
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/shareReplay';
@Injectable()
export class AuthdataService {
constructor(private http: HttpClient) {}
login(email: string, password: string) {
return this.http
.post("http://localhost:3000/user/login", {
email,
password
})
.do(res => this.setSession)
.shareReplay();
}
private setSession(authResult) {
console.log("Why am I not being hit???")
const expiresAt = moment().add(authResult.expiresIn,'second');
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem("expires_at", JSON.stringify(expiresAt.valueOf()) );
}
}
Updated solution:
login(email: string, password: string) {
return this.http
.post("http://localhost:3000/user/login", {
email,
password
})
.do(res => this.setSession(res))
.shareReplay();
}