What is the best way to check if the user is currently logged in on Angular 9? Initially, I would do it this way:
constructor(
public afAuth: AngularFireAuth,
private logger: NGXLogger
) {
this.afAuth.authState.subscribe((result) => {
if (result) {
this.user = result;
}
});
}
public isLoggedIn(): boolean {
const user = this.afAuth.currentUser;
return !!user;
}
And then call it from my component in this way:
isLoggedIn(): boolean {
return this.authService.isLoggedIn();
}
<button
*ngIf="!isLoggedIn()"
class="btn btn-glass btn-primary"
id="builder-header-create-account"
type="button"
>
Sign Up
</button>
But after upgrading to Angular 9, the above code causes my UI to hang. What is the best way of fixing it?