Firebase身份验证。$ createUserWithEmailAndPassword无效

时间:2016-11-03 10:22:51

标签: angularjs firebase firebase-authentication angularfire

我一直关注Firebase的课程,但很快发现很多事情都发生了变化。 https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-users-and-authentication-createusercredentials 这些文档已经过时了。

这里我声明了我的firebase变量

var ref = firebase.database().ref();
var firebasedata = $firebaseObject(ref);
var auth = $firebaseAuth();

然后我尝试调用此函数

this.register = function() {
  auth.$createUserWithEmailAndPassword({
    email: this.user.email, 
    password: this.user.password
  }).then(function(regUser) {
    $log.log(regUser);
  }).catch(function(error) {
    $log.log(error);
  });
};

但它引发了这个错误:

  

代码   :   “AUTH /参数错误”   信息   :   “createUserWithEmailAndPassword失败:第一个参数”email“必须是有效的字符串。”

我已经搜索了这个问题的答案,但我能找到的只是更新我的angularfire或firebase(它们都是最新版本)或者this.user.email不是字符串。当我做的时候

 console.log(this.user.email);

我可以看到它是一个包含有效电子邮件的字符串。

欢迎任何正确方向的帮助!

4 个答案:

答案 0 :(得分:2)

对于遇到此问题的任何人:

旧的

  

auth。$ createUser()

函数将user-object作为参数。

虽然:

  

auth。$ createUserWithEmailAndPassword()

将2个字符串作为参数,而不是对象。

答案 1 :(得分:1)

更改您的代码
auth.$createUserWithEmailAndPassword({
    email: this.user.email, 
    password: this.user.password
})

auth.createUserWithEmailAndPassword(user.email, user.password);

答案 2 :(得分:0)

更改功能参数如下:

this.register = function() {
  auth.$createUserWithEmailAndPassword(this.user.email,this.user.password).then(function(regUser) {
    $log.log(regUser);
  }).catch(function(error) {
    $log.log(error);
  });
};

答案 3 :(得分:0)

$scope.register = function() {
    firebase.auth().createUserWithEmailAndPassword($scope.email, $scope.password)
        .then(function(user) {
            console.log(user);
        })
        .catch(function(error) {
            console.log(error);
        });

    //}
}

在这里,您可以这样使用它。

相关问题