2014-11-23 85 views
2

我对此处于僵局。我正在尝试使用$ firebaseAuth来创建一个使用AngularFire的用户,不要使用已弃用的FirebaseSimpleLogin,正如文档中的建议。我敢肯定的是,表单提交一个有效的电子邮件和密码,但我不断收到以下错误控制台:

Error: Firebase.createUser failed: First argument must contain the key "email" with type "string"

你可以看到代码,我使用工厂服务来处理$的createUser方法,这是错误发生的地方,因为随后的console.logs在方法返回时不会触发。请注意,我也尝试在文档中使用样板代码,而不是在控制器和服务之间进行拆分,并且收到相同的错误。非常感谢您的帮助,谢谢!表格元件上

纳克提交= “寄存器()”

$scope.register = function(){ console.log($scope.user); // logs object correctly // Authentication is passed into the controller as a dependency Authentication.register($scope.user) .then(function(){ //This does NOT fire console.log("User created successfully!"); Authentication.login($scope.user);
}) .then(function(authData){ console.log("Logged in as:", authData.uid); }) .catch(function(error) { console.log('error'); $scope.errorMessage = error.toString(); }); };

认证工厂服务

var obj = { 
    register: function(user){ 
     var obj = {email: user.email, password: user.password}; 
     console.log(obj); // works correctly 
     //var auth has the reference to Firebase 
     return auth.$createUser(obj); 
    } 
}; 

回答

7

UPDATE:简单地升级到AngularFire 0.9.1或后来这个问题将被修复。

更新详情:使用单一凭证参数(如原来的提问所做的那样),现在作为AngularFire 0.9.1建议的方式来调用这个(和其他身份验证方法)。下面描述的格式已被弃用,并将在即将发布的版本中删除,因此我们不建议使用它。

这是我写文档时的错。我为完全可以理解的困惑而道歉。我想保持API与以前的AngularFire API稍微向后兼容,并决定让用户管理方法采用单独的参数,而不是像常规Firebase SDK所需的参数对象。但是,文档(和示例)并不能准确反映这一决定。您的代码应如下所示:

auth.$createUser("[email protected]", "password").then(function() { 
    console.log("User created successfully!"); 
}).catch(function(error) { 
    console.log("Error:", error); 
}); 

我会立即获得文档更新,但这里是让您畅通无阻的答案。

+0

工作,是的文档看起来像你必须传递一个对象,特别是因为$ authWithPassword需要一个对象登录。谢谢,Firebase简直太棒了! – FugueWeb 2014-11-23 21:52:35

+1

明天(星期一)第一件事将修复文档。如果您发现任何其他文档问题,请告诉我们。我们尽量保持它们尽可能准确,但它们不断得到改进。我们可能会支持将所有争论作为对象在未来通过的能力,但我需要与我的同事讨论这一点。 – jwngr 2014-11-24 01:13:29

+0

嘿@jacobawenger文档仍然不是最新的;) – qmmr 2015-01-04 20:49:19

0

我得到了同样的错误。 Angularfire 1.1或更高版本(在家代码)(更新为Bower)。我正在按照教程https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html并使用管理用户的代码。

该代码适用于硬编码字符串,例如。 [email protected]。我也找到了解决办法。如果我将对象的参数添加到$ Auth.createUser()。我也工作。我觉得像我发布的电子邮件/ pwsd文本ng-model不是一个字符串?