【问题标题】:ref.$authWithPassword is not a function in Firebaseref.$authWithPassword 不是 Firebase 中的函数
【发布时间】:2015-12-29 21:59:38
【问题描述】:

在这些日子里,一个错误跟随另一个 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('密码', { 电子邮件:用户名, 密码:密码 }) .then(函数(用户){ //成功回调 console.log('认证成功'); },函数(错误){ //失败回调 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,但无法使用我的登录/密码版本重新创建他们的选项。

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

【问题讨论】:

    标签: firebase firebase-authentication


    【解决方案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');
                });
      }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我已经尝试过(参见修改后的问题),但我现在得到:TypeError: auth.$login is not a function
      • 在我的回答或 AngularFire 文档中都没有说要使用 $login()。正如您的错误所述,这不是一个功能。 firebase.com/docs/web/libraries/angular/…
      猜你喜欢
      • 2016-12-04
      • 2018-09-28
      • 2021-12-26
      • 1970-01-01
      • 2020-12-11
      • 2021-12-30
      • 1970-01-01
      • 2018-05-28
      • 2020-04-06
      相关资源
      最近更新 更多