【问题标题】:How to push a page with onAuthStateChanged如何使用 onAuthStateChanged 推送页面
【发布时间】:2017-12-18 21:43:39
【问题描述】:

我是最新的firebase,我需要验证用户是否登录,如果是真的推送到其他页面,但什么也没发生,请帮助我! 我有这个功能

verify(){
firebase.auth().onAuthStateChanged(  function(userTester) {
    if (userTester) {
        this.navCtrl.push(ListPage);
    } else {
        console.log('nobody login');
    }
});

}

【问题讨论】:

  • console.log 部分触发了吗?
  • 不,控制台不显示任何东西,我在真实情况下放了一个console.log,并触发警报
  • 所以如果不推送console.log肯定是触发了。
  • 我之前在true中放置了一个console.log并显示了消息

标签: angular firebase firebase-authentication ionic3


【解决方案1】:

我创建了下面的函数来帮助我。我在 auth.service.ts 中创建了它。

isLoggedIn() {
    this.afAuth.auth.onAuthStateChanged(auth => {
      // Now use value 
      if (auth) {
        // logged in
        console.log('this is their UID: ' + auth.uid);
        console.log('Routing to items');
        this.router.navigate(['/items']);
      } else {
        // logged out
        console.log('User logged out');
      }
    });
  }

上面的控制台日志是为了验证我是否能够看到它。然后我只是在有人登录时调用它:

googleLogin() {
    const provider = new firebase.auth.GoogleAuthProvider()
    this.isLoggedIn();
    return this.oAuthLogin(provider);
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    相关资源
    最近更新 更多