colin_dev256 colin_dev256 - 3 months ago 93
AngularJS Question

Angularfire firebase-authentication - google

I'm struggling to implement firebase-authentication for angularfire even with this tiny example. There's not much I can get from the google docs since they mostly address js web and not angularfire stuff. Firebase legacy docs for angularfire are deprecated as of May 18, 2016. Anyone able to help with the new implementation or post me the relevant link?

So far I get a;



TypeError: classifiedsFactory.$authWithOAuthPopup is not a function



error in the console when I click the login button so it's ($authWithOAuthPopup) clearly outdated.

classifieds.fac.js (factory)

(function() {

"use strict";

angular
.module("ngClassifieds")
.factory("classifiedsFactory", function($firebaseAuth) {

return $firebaseAuth();

});
})();


classifieds.ctr.js (controller)

(function() {

"use strict";

angular
.module("ngClassifieds")
.controller("classifiedsCtrl", function($scope, $firebaseArray, classifiedsFactory) {

$scope.login = function(){
classifiedsFactory.$authWithOAuthPopup('google').then(function(authData) {
console.log(authData);
}).catch(function(error) {
console.error(error)
})
}

$scope.logout = function(){
classifiedsFactory.$unauth();
}



});

})();


Login buttons in html

<md-button ng-click="login()">
Login with Gmail
</md-button>

<md-button ng-click="logout()">
Logout
</md-button>

Answer

$firebaseAuth().$authWithOAuthPopup (legacy documentation) is deprecated since the realease of firebase 3.0.

You should use $signInWithPopup instead.

classifiedsFactory.$signInWithPopup("google").then(function(result) {
  console.log("Signed in as:", result.user.uid);
}).catch(function(error) {
  console.error("Authentication failed:", error);
});

You can find some detailed angularfire documentation here.