Ionic 2 - Bug after make login with Facebook native and go to a tab page
After using with native Facebook i did:
loginWithFacebook() {
this.platform.ready().then(() => {
Facebook.login(["public_profile", "user_birthday"]).then(() => {
this.nav.setRoot(TabsPage);
}, (...args) => {
console.log(args);
});
});
}
Whatever page works, except of type tabs. I tried with setRoot and push but without success
Hello! Thanks for opening an issue with us! As this issue is more related to Ionic-Native and not the framework itself i will be moving this issue to over there. Thanks for using Ionic!
This issue was moved to driftyco/ionic-cli#957
Hello all! Is this still an issue with the latest version of ionic? Thanks!
Hello all! As it seems it has been a while since there was any activity on this issue i will be closing it for now. Feel free to comment if you are still running into this issue. Thanks for using Ionic!
Hey unfortunately still experiencing this issue - using beta.11. Is anyone experiencing this issue in rc0? Maybe it is fixed in the new version. Thanks.
@matejamateusz i was facing the same problem, it is not a navigation problem, but here is how i solved it.
in my app.ts is have this
firebase.initializeApp(config);
platform.ready().then(() => { firebase.auth().onAuthStateChanged((user) => { if (user) { // If there's a user take him to the TabsPage page. this.rootPage = TabsPage; } else { // If there's no user logged in send him to the LoginPage this.rootPage = LoginPage; } }); // 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 if statement above is saying // If there's a user SET THE ROOTPAGE TO TabsPage page. and else it should remain in the LoginPage, you will note that if you use normal firebase login method, the if part will execute (i.e it will navigate to the rootPage, but when using Facebook the else part will execute (i.e it stays on the LoginPage
I solved it like this. facebookLogin() {
//sign in to facebook Facebook.login(['email']).then((result=>{ // set credentials, you will use this to sign in to firebase let credentials = firebase.auth.FacebookAuthProvider'credential' // sign in to firebase, this is what is preventing the navigation to work, leading to the ELSE path of the //statement in the app.ts to execute
return firebase.auth().signInWithCredential(credentials); })).then((user)=>{ //alert(firebase.auth().currentUser.uid); this.userProfileRef.child(firebase.auth().currentUser.uid).set({ id:firebase.auth().currentUser.uid, email: user.email, displayName:user.displayName, profilePictureURL:user.photoURL });
this.navCtrl.setRoot(TabsPage); }).catch((error)=>{ alert(error); }) }
what happened in the code above is that, 1st you need to login to facebook, which i did with Facebook.login(['email']).then((result=>
2nd you need to set a credentials that will help you login to the firebase using the accessToken sent to you by Facebook login result which is what i did here let credentials = firebase.auth.FacebookAuthProvider'credential'; 3rd you need to login to firebase with credentials you set, which is what i did here return firebase.auth().signInWithCredential(credentials); NOTE: this the exact reason why your this.navCtrl.setRoot(TabsPage); did not work (because the user is yet to login on firebase.
so you can now navigate to the rootPath at the then() path of the code.
and please kindly make sure you your facebook appId and appSecrete is configured on firebase>authentication>facebook panel.
HOPE THIS HELP
I'm experiencing a variation of this issue with Ionic. If you try to push a Tabs page to the nav stack on facebook success, somehow the Tabs page pushes a duplicate of whatever the first tab is.
Say you have 3 tabs [Home, About, contact] On a different page without tabs, on facebook login success, push the tabs page to the nav stack, and the inner stack of the tabs page will have TWO "Home" pages. It's insane. If you select the "Home" tab, it will of course drop the layered Home page from the stack, and then the nav buttons no longer color on tap.
Here's the problem I'm having: https://github.com/driftyco/ionic/issues/9772
I hope it helps anyone pulling their hair out over it
I have workaround for this since last beta.. basically, all I did was to create an intermediate redirect page.. so, instead of pushing to the tab page right away, i'll push to the nav stack this temporary page which will then again make a redirect to the page with the tabs on.. it solve most of the problems dealing with tabs page for me.. just a workaround.. not a valid solution though..
Note: HomePage is the one with the tabs on
import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';
import {HomePage} from '../home/home'
import {UserProfileHomePage} from '../profile/home'
import {CreateTeamPage} from '../teams/create-team'
@Component({
template: ''
})
export class PreparePage {
pages = {
'HomePage': HomePage,
'UserProfileHomePage': UserProfileHomePage,
'CreateTeamPage': CreateTeamPage
}
constructor(private nav: NavController, private param:NavParams) {
}
ionViewDidEnter() {
if(typeof this.param.get('redirect') !== 'undefined'){
// if you wish to set tab page as root
if(typeof this.param.get('setroot') !== 'undefined'){
this.nav.setRoot(this.pages[this.param.get('redirect')])
}
else{
// if you want to pass any data as object named data { data: {foo:bar} }
if (this.param.get('data') !== 'undefined'){
this.nav.push(this.pages[this.param.get('redirect')], this.param.get('data')).then(() => {
this.nav.remove(this.nav.length() - 2)
})
}
else{
this.nav.push(this.pages[this.param.get('redirect')]).then(() => {
this.nav.remove(this.nav.length() - 2)
})
}
}
}
}
} // end class block
@lufias Nice one :) Many thanks!
This still isn't working for me no matter where I put this.navCtrl.setRoot(HomePage);facebookLogin() {this.facebook.login(['email', 'public_profile']).then(result=>{const credentials=firebase.auth.FacebookAuthProvider.credential(result.authResponse.accessToken);firebase.auth().signInWithCredential(credentials).then((success)=>{this.userProfile = success;this.firebaseLogin.setUpUser(credentials, success);})}).catch(err=>{alert(JSON.stringify(err))})this.navCtrl.setRoot(HomePage); }
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.