Reputation: 7692
I'm trying to learn angularfire and add some auth to my site. But it doesn't work as expected. I can't understand why this part isn't working dynamically
@HostBinding('class') classes = (this.isLoggedIn())
? 'navbar navbar-expand-md sticky-top navbar-dark bg-dark'
: 'navbar navbar-expand-md sticky-top navbar-light bg-light';
It works once at init. But then nothing is happening. This is my service
@Injectable({
providedIn: 'root'
})
export class AuthService {
private user: Observable<firebase.User>;
private userDetails: firebase.User = null;
constructor(
private _firebaseAuth: AngularFireAuth,
private router: Router
) {
this.user = _firebaseAuth.authState;
this.user.subscribe(
user => {
if (user) {
this.userDetails = user;
console.log(this.userDetails);
} else {
this.userDetails = null;
}
}
);
}
signInWithFacebook() {
return this._firebaseAuth.auth.signInWithPopup(
new firebase.auth.FacebookAuthProvider()
);
}
isLoggedIn(): boolean {
return this.userDetails != null;
}
logOut(): void {
this._firebaseAuth.auth.signOut()
.then(res => this.router.navigate(['/']));
console.log('logged out');
}
}
Upvotes: 0
Views: 68
Reputation: 2580
Could it be that it's just called once -- you gotta have an observable or something that will fire an event to set classes? IsLoggedIn() is just a function, on NgOnit probably just gets invoked once and then never again.
Upvotes: 1