我根据Firebase在http://jsfiddle.net/firebase/a221m6pb/
提供的示例对我的Google登录进行了建模然而,当我运行我的代码( https://firetest-wadeziegler.c9.io/logon )时,弹出窗口在选择用户后变为空白而从未关闭。永远不会执行回调代码。任何想法为什么这不起作用?
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();
}
答案 0 :(得分:2)
问题在于调用代码和表单中的点击缺少preventDefault()
。点击后立即重新加载页面,但它很快我没注意到。愚蠢的错误。
<button onClick="logonWithGoogle(); return false /* prevent submit */">