Cannot read property 'email' of null


#1
export class User {
  email:string ;
  password: string;
}
import { Component, ViewChild } from '@angular/core';
import { Platform, Nav } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { CalcularRotaPage } from '../pages/calcular-rota/calcular-rota';
import { LoginPage } from '../pages/login/login';
import { FretesPage } from '../pages/fretes/fretes';
import { FretesAdminPage } from '../pages/fretes-admin/fretes-admin';
import { SignupPage } from '../pages/signup/signup';
import { ConexaoProvider } from '../providers/conexao/conexao';

import { AngularFireAuth } from 'angularfire2/auth';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) navCtrl: Nav;
    rootPage:any;

  constructor(
    platform: Platform,
    statusBar: StatusBar,
    splashScreen: SplashScreen,
    private conexaoProvider: ConexaoProvider,
    afAuth: AngularFireAuth) {
    const authObserver = afAuth.authState.subscribe(user => {
      if(user.email.search('@simetransportes.com.br')!=-1) {
        this.rootPage = FretesAdminPage;
        authObserver.unsubscribe();
      } else if(user) {
        this.rootPage = FretesPage;
        authObserver.unsubscribe();
      } else {
        this.rootPage = LoginPage;
        authObserver.unsubscribe();
      }
    });

    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });
  }

  goToFretes(params){
    if (!params) params = {};
    this.navCtrl.setRoot(MyApp);
  }
  goToCalcularRota(params){
    if (!params) params = {};
    this.navCtrl.setRoot(CalcularRotaPage);
  }
  goToCriarUsuario(params){
    if (!params) params = {};
    this.navCtrl.setRoot(SignupPage);
  }
  doLogout(){
    this.conexaoProvider.signOut()
    .then(() => {
      this.navCtrl.setRoot(LoginPage);
    })
    .catch((error) => {
      console.error(error);
    });
  }
}