【问题标题】:Firebase auth().onAuthStateChanged()Firebase auth().onAuthStateChanged()
【发布时间】:2016-12-29 10:52:05
【问题描述】:

我在我的 Ionic 应用程序中使用了 auth().onAuthStateChanged() 所以当用户登录时,应用程序转到用户配置文件 $state 但问题是,因为观察者不断检查我无法检查的更改更改 $state,每当我尝试时,它都会更改回用户配置文件 $state。

    firebase.auth().onAuthStateChanged(function(user) {
    $scope.currUser = user;
    if (user) {
        $scope.go('profile') //function to change states.
    } else {
    // No user is signed in.
        $scope.go("login") //login is where the app starts (login page)
    }
    });

现在,当我处于配置文件 $state 并尝试转到另一个状态时 - 例如仪表板,它会在一秒钟内自行返回到配置文件状态。

请帮我解决这个问题并提前感谢

【问题讨论】:

    标签: angularjs ionic-framework firebase firebase-authentication


    【解决方案1】:

    如果只需要验证用户是否登录过一次,可以退订观察者。

    var unsubscribe = firebase.auth().onAuthStateChanged(function(user) {
        unsubscribe();
        $scope.currUser = user;
        if (user) {
            $scope.go('profile') //function to change states.
        } else {
        // No user is signed in.
            $scope.go("login") //login is where the app starts (login page)
        }
        });
    

    【讨论】:

      猜你喜欢
      • 2020-02-15
      • 1970-01-01
      • 2020-09-22
      • 2021-11-08
      • 2021-07-15
      • 2017-11-10
      • 2020-11-15
      • 2019-03-30
      • 1970-01-01
      相关资源
      最近更新 更多