0

在这些天中,一个错误跟随另一个 jeezzz... 使用 firebase 作为我的应用程序的简单数据源非常重要。当它崩溃时,我正要开始实施$firebaseSimpleLogin,但我发现虽然 stackoverflow 它已被弃用,取而代之的是$firebaseAuth. 但是,现在我无法更新控制器中的函数,因为它一次又一次地抛出相同的错误:

TypeError: ref.$authWithPassword 不是函数

我已将所有依赖项添加到我的控制器,从我的 firebase 源创建了 ref 对象,但仍然不允许我的用户(已经创建)登录 i。这是代码:

controllersModule.controller('HomeCtrl',  ["$scope", "$firebaseAuth",
  function($scope, $firebaseAuth) {
    var ref = new Firebase("https://<MYUSERAPI>.firebaseio.com");
     var auth = $firebaseAuth(ref);

  $scope.user = {};
  $scope.SignIn = function(e){
     e.preventDefault();
     var username = $scope.user.email;
     var password = $scope.user.password;

//修正 - 仍然收到错误 auth.$login('password', { email: username, password: password }) .then(function(user) { //Success callback console.log('Authentication succeed'); } , function(error) { //失败回调 console.log('认证失败'); }); } }]);

它告诉我 at ref.$authWithPassword 不是函数?我错过了一个插件吗?

我有以下版本的 firebase 和 Angular fire:

          <script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
          <script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>

我已经进入此页面https://www.firebase.com/docs/web/guide/login/password.html,但无法使用我的登录/密码版本重新创建他们的选项。

非常感谢任何帮助,尤其是今天。谢谢。

4

2 回答 2

1

我已经通过返回 $authWithPassword 并按照 Anid 的帖子添加身份验证来修复它,它可以工作。

$scope.user = {};
  $scope.SignIn = function(e){
     e.preventDefault();
     var username = $scope.user.email;
     var password = $scope.user.password;
     auth.$authWithPassword ({
                email: username,
                password: password
            })
            .then(function(user) {
                //Success callback
                console.log('Authentication successful');
            }, function(error) {
                //Failure callback
                console.log('Authentication failure');
            });
  }
于 2015-10-01T19:14:33.177 回答
0

$authWithPassword是 AngularFire 方法,而不是 Firebase 参考方法。您应该在auth变量上调用该方法。

于 2015-10-01T18:40:09.397 回答