Nachdem ich mich anmelde, authservice aufgerufen wird und dann das Routing auf die Profilkomponente funktioniert.angular 5 Post-Anfrage kehrt zweimal zurück
Allerdings wird die Post-Anfrage zweimal gesendet, ich verwende nicht Cors, also nehme ich an, dass dies keine Preflight-Anfrage sein kann? Profile.componence.ts ngoninit scheint zweimal zu laufen, da ich zuerst coinId mit der richtigen ID gefolgt von einer undefinierten coinId erhalte.
5a273e34f5c5643e18c035dacoinId from profile2!
main.f2eaf663cdbf963d2af8.bundle.js:1 undefinedcoinId from profile2!
Ich bin ganz neu auf all dies, ich bin erwägen einen nginx Server gestartet, aber nicht sicher, ob das dieses Problem lösen würde.
login.component.ts
let url = 'http://localhost:3000/api/login';
this.newService.login(url, user, user.username).subscribe(result => {
var value = result["user"];
var coinId = result.user.coinid;
this.router.navigate(['/profile', coinId]);
auth.service.ts
login(url: string, user: any, username: any)
{return this.http.post(url , user)
.do (res => this.setSession(res))
}
private setSession(authResult) {
const expiresAt = moment().add(authResult.expiresIn,'second');
this.loggedIn.next(!!localStorage.getItem('id_token'));
console.log(authResult.token + "dit is de token");
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem("expires_at", JSON.stringify(expiresAt.valueOf()));
}
profile.component.ts
ngOnInit() {
var coinId = this.route.snapshot.params['id'];
console.log(coinId + "coinId from profile2!")
this.router.navigate([ '/profile', {outlets: { formOutlet:
['profileform', coinAId]}}]);
}