Well, I’m testing a app with firebase, and I using a auth by Email, but I’m using firebase.auth() to look if the user is already logged in, the code looks to be right for me, but the rootPage does not recive nothing! Someone can help me?
import { Component, ViewChild } from '@angular/core';
import { Platform, NavController, MenuController } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { Login } from '../pages/login/login';
import { Clientes } from '../pages/clientes/clientes';
import firebase from 'firebase';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild('conteudo') nav : NavController;
public pages: any;
public clientes: any;
private rootPage: any;
constructor(platform: Platform, private menu:MenuController) {
this.menu = menu;
this.pages = [
{ title: 'Home', component: HomePage, icon: "home"},
];
this.clientes = [
{ title: 'Clientes', component: Clientes, icon: "md-contact"},
{ title: 'Banco de Horas', component: HomePage, icon: "ios-timer"},
{ title: 'Reservas', component: HomePage, icon: "calendar"},
];
var config ={
apiKey: "<MY API KEY>",
authDomain: "<MY DOMAIN>",
databaseURL: "<MY DATABASE URL>",
storageBucket: "< MY STORAGE BUCKET>"
}
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.rootPage = HomePage;
} else {
this.rootPage = Login;
}
});
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
});
}
openPage(page) {
this.menu.close();
this.nav.setRoot(page.component);
};
}