Created
October 14, 2016 13:09
-
-
Save javebratt/c69591a4b147e85cd40618f6bc562463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { Platform } from 'ionic-angular'; | |
import { StatusBar } from 'ionic-native'; | |
import { HomePage } from '../pages/home/home'; | |
import { LoginPage } from '../pages/login/login'; | |
import firebase from 'firebase'; | |
@Component({ | |
template: `<ion-nav [root]="rootPage"></ion-nav>` | |
}) | |
export class MyApp { | |
rootPage: any; | |
constructor(platform: Platform) { | |
firebase.initializeApp({ | |
apiKey: "", | |
authDomain: "", | |
databaseURL: "", | |
storageBucket: "", | |
messagingSenderId: "" | |
}); | |
let unsubscribe = firebase.auth().onAuthStateChanged((user) => { | |
if (user) { | |
this.rootPage = HomePage; | |
console.log("HomePage", user); | |
unsubscribe(); | |
} else { | |
this.rootPage = LoginPage; | |
console.log("LoginPage", user); | |
unsubscribe(); | |
} | |
}); | |
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(); | |
}); | |
} | |
} | |
/** | |
* The code works with Firebase, I get back the user and log it to the console, | |
* but it's not assigning the rootPage. | |
* | |
* Or it is, because if I log it I get the correct value, but is not redirecting to it. | |
*/ | |
// However, if I just do | |
rootPage = LoginPage; | |
// It goes to the login page. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Finaly i can fixed using something like this:
import { Component, ViewChild } from '@angular/core';
import { Nav } from 'ionic-angular';
@component({
template:
<ion-nav [root]="rootPage"></ion-nav>
})
export class MyApp
{
@ViewChild(Nav) nav: Nav;
......
firebase.auth().onAuthStateChanged((user) =>
{
if (user)
this.nav.setRoot(SlideMenuPage);
else
this.nav.setRoot(LoginPage);
});
}
And it's working.
Please some coments that i need know using this method?
Kind regards