redrockzee
redrockzee

Reputation: 555

Why doesn't my Google authentication work in Firebase?

I've modeled my Google logon after the example provided by Firebase at http://jsfiddle.net/firebase/a221m6pb/

However when I run my code (https://firetest-wadeziegler.c9.io/logon) the popup goes blank after selecting user and never closes. The callback code is never executed. Any ideas why this isn't working?

Authorized Domains for OAuth Redirects:

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

Upvotes: 1

Views: 406

Answers (1)

redrockzee
redrockzee

Reputation: 555

The problem was with the calling code and the lack of a preventDefault() on the click within a form. The page reloaded right after the click but it was so quick I didn't notice. Stupid mistake.

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

Upvotes: 2

Related Questions