2

关于stackoverflow的第一个问题,如果我的信息不足,请告诉我。提前致谢。

我正在尝试实现 firebase-simple-login,但我得到的唯一错误类型是 signIn 函数上的“INVALID EMAIL”。如果我在现有电子邮件中输入了错误的密码,它仍然会抛出无效的电子邮件。

$scope.signIn = function() {
        $rootScope.auth.$login('password', {
            email: $scope.email,
            password: $scope.password
        }).then(function(user) {
            console.log("user has email " + user.email);
        }, function(error) {
            if (error = 'INVALID_EMAIL') {
                console.log('email invalid or not signed up');
            } else if (error = 'INVALID_PASSWORD') {
                console.log('invalid password');
            } else {
                console.log(error);
            }
        });
    };

供额外参考;对应表单的html

<div class="form-group">
    <input type="email" class="form-control" placeholder="email" ng-model="email" />
</div>
<div class="form-group">
    <input type="password" class="form-control" placeholder="password" ng-model="password" />
</div>
<button type="submit" class="btn btn-success" ng-click="signIn()">Sign in</button>

我似乎在 firebase 文档中找不到任何关于错误类型的有用信息,所以我希望你能提供帮助。

CreateUser 被这样调用:

 $scope.signUp = function() {
        $rootScope.auth.$createUser($scope.email, $scope.password, function(error,user) {
            if (!error) {
                console.log('User Id: ' + user.uid + ', Email: ' + user.email);
            }
        }).then(function(){
            $rootScope.auth.$login('password', {
                email: $scope.email,
                password: $scope.password
            });
        });
    };
4

2 回答 2

1

这是我在进一步检查错误函数后找到的解决方案。看来您需要进入错误对象,而error.code不是 just error,以及使用运算符===而不是=. 我已经$login()从 firebase 文档中直接删除了,但我可能在此过程中混淆了一些东西。无论如何,这是工作代码。

function(error) {
            if (error.code === 'INVALID_EMAIL') {
                console.log('email invalid or not signed up');
            } else if (error.code === 'INVALID_PASSWORD') {
                console.log('invalid password');
} 
于 2014-06-27T11:13:53.470 回答
0

您实际上可以使用 Firebase 提供的错误消息而不是 if 子句。

function(error){
  if(error){
    console.log(error_code.message)
  }
}
于 2014-09-06T06:35:03.447 回答