angularFire auth。$ signOut不触发.then()函数

时间:2016-09-30 15:00:34

标签: javascript angularjs firebase firebase-authentication

我试图从我的节点服务器返回数据,几乎所有东西似乎都有效。此代码正确地将数据返回给经过身份验证的用户,并拒绝未经过身份验证或出现无效令牌的用户。

唯一不起作用的是firebase $ signOut函数,当我点击该代码时,我只想记录。 $ onAuthStateChanged正确触发并记录“尚未登录”。但$ signOut不会记录'将用户注销!'喜欢它。相反,它会给出错误:Cannot read property 'then' of undefined

var app = angular.module("sampleApp", ["firebase"]);
app.controller("SampleCtrl", function($scope, $firebaseArray, $firebaseAuth, $http) {
  var auth = $firebaseAuth();

  $scope.logIn = function login(){
    auth.$signInWithPopup("google").then(function(firebaseUser) {
      console.log("Signed in as:", firebaseUser.user.displayName);
    }).catch(function(error) {
      console.log("Authentication failed: ", error);
    });
  };

  auth.$onAuthStateChanged(function(firebaseUser){
    // can we get back to our server?
    if(firebaseUser) {
      $http({
        method: 'GET',
        url: '/secretData',
        headers: {
          id_token: firebaseUser.kd
        }
      }).then(function(response){
        $scope.secretData = response.data;
      });
    }else{
      console.log('Not logged in yet.');
      $scope.secretData = "Log in to get some secret data."
    }

  });

  $scope.logOut = function(){
    console.log(auth);
    auth.$signOut().then(function(){
      console.log('Logging the user out!'); // The only line that doesn't seem to be working
    });
  };
});

我对文档的理解让我觉得这应该有用,因为它是一个承诺? https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signOut

我也尝试将其作为回调传递,我认为不对,这不会抛出错误或记录所需的console.log

auth.$signOut(function(){
  console.log('Logging the user out!'); // The only line that doesn't seem to be working
});

0 个答案:

没有答案