首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理Firebase web中的auth/argument-error?

如何处理Firebase web中的auth/argument-error?
EN

Stack Overflow用户
提问于 2016-11-07 21:45:54
回答 2查看 6.3K关注 0票数 4

我正在处理一个使用Firebase的web项目,我需要处理登录页面上的所有身份验证错误。

为什么我不能像其他人一样得到等于‘auth/argument- error.code’的错误代码呢?

例如,当我有一个登录表单,在没有填写电子邮件和密码的情况下按下按钮时,控制台中会抛出以下错误:

如何获取此错误对象并将其保存在变量中?

@Frank van Puffelen,请接电话

signin.js

代码语言:javascript
复制
vm.signIn = function() {
        vm.loading = true;
        return $q(function(resolve, reject) {
            firebaseAuth.$signInWithEmailAndPassword(vm.email, vm.password)
                .then(function(firebaseUser) {
                    console.log('[Firebase] User signed as', firebaseUser);
                    vm.loading = false;
                    resolve();
                    $state.go('main');
                }).catch(function(error) {
                    console.error('[Code]', error.code);
                    console.error('[Message]', error.message);
                    switch (error.code) {
                        case 'auth/argument-error':
                            vm.translationId = 'IT DOENST WORK LIKE ERRORS BELOW';
                            console.log('IT DOENST WORK LIKE ERRORS BELOW');
                            break;
                        case 'auth/wrong-password':
                            vm.translationId = 'FIREBASE.AUTH.WRONG_PASSWORD.ERROR_MSG';
                            break;
                        case 'auth/user-not-found':
                            vm.translationId = 'FIREBASE.AUTH.USER_NOT_FOUND.ERROR_MSG';
                            break;
                        case 'auth/user-disabled':
                            vm.translationId = 'FIREBASE.AUTH.USER_DISABLED.ERROR_MSG';
                            break;
                        case 'auth/invalid-email':
                            vm.translationId = 'FIREBASE.AUTH.INVALID_EMAIL.ERROR_MSG';
                            break;
                        default:
                            vm.loading = false;
                            vm.translationId = error.message;
                    }
                    $translate(vm.translationId)
                        .then(function(translated) {
                            vm.loading = false;
                            toastr.error(translated);
                        }, function(translationId) {
                            // NOTE: Validar quando o catch dispara!
                            vm.translationId = translationId;
                        });
                    vm.loading = false;
                    reject();
                });
        });
    };
EN

回答 2

Stack Overflow用户

发布于 2017-03-25 14:24:53

当未向firebase提供电子邮件或密码,并且无法在catch块中处理时,就会发生这种情况。因为它是一个参数错误。下面的代码检查电子邮件和密码是否存在,然后只调用firebase.auth()

代码语言:javascript
复制
$scope.login = function(data){
    $scope.err = null;
    $scope.busy = true;
    if(!data || !data.email || !data.password){
        $timeout(function(){
            $scope.err = {
                code:'InvalidParms',
                message: "Please provide correct email."
            };
            $scope.busy = false;
        },0);
        return;
    }

    firebase.auth().signInWithEmailAndPassword(data.email,data.password).then(function(res){
        if(res){                                    
            $rootScope.user = res;
            if(res.emailVerified){
                $location.path('/');
            }else{
                $timeout(function(){
                    $scope.err = {
                        code:'EmailNotVerified',
                        message: "You email is not yet verified. Please verify your email. Click on resend verification mail if you haven't got a verification mail from us."
                    };
                },0);
            }
            //
        }
        $scope.busy = false;
    }).catch(function(err){
        $timeout(function(){
            console.log(err);
            $scope.busy = false;
        },0);

    });


};
票数 3
EN

Stack Overflow用户

发布于 2022-02-21 12:20:37

我认为这是RecaptchaVerifier的问题所在

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40466753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档