即使有了这个小例子,我也在努力为 AngularFire 实现 Firebase 身份验证。我从谷歌文档中能得到的信息并不多,因为它们主要解决 js web 而不是 Angularfire 的问题。自 2016 年 5 月 18 日起,Angularfire 的 Firebase 旧版文档已弃用。任何人都可以帮助实现新的实现或向我发布相关链接吗?
到目前为止我得到了;
block 引用>TypeError: classifiedsFactory.$authWithOAuthPopup is not a function
当我单击登录按钮时,控制台中出现错误,因此它 ($authWithOAuthPopup) 显然已经过时了。
classifieds.fac.js(工厂)
(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(); } }); })();
html 中的登录按钮
<md-button ng-click="login()"> Login with Gmail </md-button> <md-button ng-click="logout()"> Logout </md-button>
最佳答案
$firebaseAuth().$authWithOAuthPopup
( legacy documentation ) 自 Firebase 3.0 发布以来已被弃用。
您应该使用 $signInWithPopup
来代替。
classifiedsFactory.$signInWithPopup("google").then(function(result) {
console.log("Signed in as:", result.user.uid);
}).catch(function(error) {
console.error("Authentication failed:", error);
});
你可以找到一些详细的 AngularFire 文档 here .
关于javascript - Angularfire firebase 身份验证 - 谷歌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39150210/