Ionic 2 google signin with firebase

后端 未结 1 826
野性不改
野性不改 2021-01-26 01:30

im getting some troubles with firebase authentication and google provider. Im trying to signin with google provider (this works fine) but then i want to redirect to my homepage

相关标签:
1条回答
  • 2021-01-26 01:59

    I read the comments so this is now a 2 part question:

    1) For Google Auth, the signInWithRedirect() and signInWithPopUp() methods don't work in cordova/ionic apps yet.

    You'll need to use the Google native plugin to get the login credentials and then you can pass them to firebase.auth.signInWithCredentials()

    2) About the bug sending you to the HomePage:

    There's a weird bug in Ionic's navCtrl that isn't pushing the page after it returns with the user in:

    firebase.auth().onAuthStateChanged((user) => {
      if (!user) {
        this.nav.setRoot(Home);
      } else {
        this.nav.setRoot(Menu);
      }
    });
    

    I got that working by simply declaring rootPage: any = Menu; and then doing this instead:

    firebase.auth().onAuthStateChanged((user) => {
      if (!user) {
        this.nav.setRoot(Home);
      }
    });
    
    0 讨论(0)
提交回复
热议问题