Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created June 25, 2019 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/2048ab5f6d6958a2ebc9240beb00ab2d to your computer and use it in GitHub Desktop.
Save gavilanch/2048ab5f6d6958a2ebc9240beb00ab2d to your computer and use it in GitHub Desktop.
export class AppComponent implements OnInit {
 user: User; 
 constructor(private afAuth: AngularFireAuth,
   private router: Router,
   private ngZone: NgZone){}
 ngOnInit(){
   this.afAuth.user.onAuthStateChanged(user => {
     if (user){
       this.user = user;
     } else{
  this.user = null;
       this.ngZone.run(() => {
         this.router.navigate(['']);
       })
   });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment