javascript - 身份验证在 ionic 和 Firebase 中始终处于事件状态

标签 javascript angularjs ionic-framework firebase angularfire

我正在使用 ionic 和 firebase,但我的 View 登录遇到问题。

登录 View 始终显示为已通过身份验证,但在此 View 中用户尚未登录

我需要做什么才能显示未经身份验证的此 View ?因为用户尚未登录

PS:我正在使用 Facebook 社交身份验证。

.controller('BeforeLoginCtrl', function($scope, $state, $rootScope, $firebaseAuth, Auth) {
  /*$scope.login = function() {
    $state.go('login');
  };

  $scope.signUp = function() {
    $state.go('signup');
  };*/

  Auth.$onAuth(function(authData){
    if (authData === null) {
      console.log("No autheticathed");
    } else {
      console.log("Authenticated");
      /*$state.go('tab.dash');*/
    }

    $scope.authData = authData;
  });

  $scope.loginFacebook = function(){
    Auth.$authWithOAuthRedirect("facebook").then(function(authData) {

    }).catch(function(error) {
      if (error.code === 'TRANSPORT_UNAVAILABLE') {
        Auth.$authWithOAuthpopup("facebook").then(function(authData){

        });
      } else {
        console.log(error);
      }
    });
  };
})

.factory('Auth', function($firebaseAuth) {
    var endpoint = "https://<NAME>.firebaseio.com/users";
    var usersRef = new Firebase(endpoint);

    return $firebaseAuth(usersRef);
});

最佳答案

如果 Auth.$onAuth(function(authData) 为您提供身份验证数据,您可以非常确定用户实际上已通过身份验证。

请记住,Firebase 会“记住”页面转换之间的身份验证状态。这在幕后透明地发生,您无需为其编写任何代码。

如果您想强制用户注销,请调用$unauth()

关于javascript - 身份验证在 ionic 和 Firebase 中始终处于事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35351505/

相关文章:

angularjs - 在 View 进行ng-animate期间, "leaving" View 在动画中时, "entering" View 仍会占用空间

javascript - ionic $stateParams 未定义

ionic-framework - ionic 2/ ionic 3-垃圾收集

javascript - 为什么 document.onreadystatechange 运行两次?

javascript - html 表单中的 jQuery 对话框表单

javascript - 将返回 promise 的函数置于 redux 状态

javascript - ionic react ,滚动到特定列表项

javascript - 我如何只在 div 而不是 div : hover by CSS and JavaScript 上应用动态宽度

angularjs - 无法让 $templateCache 工作

angularjs - 将 AngularJS 与 Oracle Apex 结合使用