为什么我的Google身份验证无法在Firebase中使用?

时间:2015-07-06 20:06:34

标签: javascript callback popup firebase google-authentication

我根据Firebase在http://jsfiddle.net/firebase/a221m6pb/

提供的示例对我的Google登录进行了建模

然而,当我运行我的代码( https://firetest-wadeziegler.c9.io/logon )时,弹出窗口在选择用户后变为空白而从未关闭。永远不会执行回调代码。任何想法为什么这不起作用?

OAuth重定向的授权域:

firetest-wadeziegler.c9.io

logon.js

function logonWithGoogle() {
  var promise = session.logonWithGoogle();

  $.when(promise)
    .then(function (authData) {
      setTimeout(function() { window.location.replace('/') }, 0);
  }, function (error) {
    showMessageBox('Logon Failed', error);
  });
}

session.js     var session = new Session();

function Session() {
  this.firebase = new Firebase("https://glowing-inferno-3026.firebaseio.com");
  this.firebase.onAuth(function globalOnAuth(authData) { } );
}

Session.prototype.isLoggedOn = function() {
  return this.firebase.getAuth() != null;
}

// Returns Promise object
Session.prototype.logonWithGoogle = function() {
  var deferred = $.Deferred();

  this.firebase.authWithOAuthPopup("google", 
    function (err, user) {
      if (err) {
          deferred.reject(err);
      }

      if (user) {
          deferred.resolve(user);
      }
    }
    , {
      remember: "sessionOnly",
      scope: "email,profile"
    });

  return deferred.promise();
}

1 个答案:

答案 0 :(得分:2)

问题在于调用代码和表单中的点击缺少preventDefault()。点击后立即重新加载页面,但它很快我没注意到。愚蠢的错误。

<button onClick="logonWithGoogle(); return false /* prevent submit */">