Reputation: 562
When I call login()
or logout()
in auth.service.ts from login.ts component after showing facebook popup, the isAuth
remain false in the home view but if I do console.log(this.isAuth)
inside subscribe()
it updates correctly in console.
When I call login()
or logout()
directly without using firebase facebook login, It works fine.
Home
HTML
<h1> {{isAuth}} </h1>
TS
isAuth = false;
constructor(private _auth:AuthService) {
_auth.authState.subscribe(state => this.isAuth = state)
}
AuthService
authState = new Subject<boolean>();
login(access_token) {
this.authState.next(true);
}
logout() {
this.authState.next(false);
}
Subject is imported from
import { Subject } from "rxjs/Subject";
login.ts
signInWithFacebook() {
this.afAuth.auth
.signInWithPopup(new firebase.auth.FacebookAuthProvider())
.then((res: any) => {
const access_token = res.credential.accessToken;
this._auth.login(access_token);
this._router.navigateByUrl('/home');
});
the facebook promise is solved and the this._auth.login()
is called and the isAuth
is changed but the view is not updated...
Upvotes: 0
Views: 153
Reputation: 43
Perhaps you can try NgZone
ts
isAuth = false;
constructor(private _auth:AuthService, private ngZone: NgZone) {
ngZone.run(() => {
_auth.authState.subscribe(state => this.isAuth = state)
});
}
Upvotes: 1