为什么我的Google身份验证不能在Firebase中工作?

Why doesn't my Google authentication work in Firebase?

本文关键字:Firebase 工作 不能 我的 Google 身份验证 为什么      更新时间:2023-09-26

我在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();
}

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

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