简体   繁体   English

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

[英]How to handle with auth/argument-error in Firebase web?

I am working on a web project using Firebase, and I need to handle all authentication errors on the signin page.我正在使用 Firebase 处理 web 项目,我需要处理登录页面上的所有身份验证错误。

Why I can't get the error.code equals 'auth/argument-error' like I do with others 'auth/something-error' error codes?为什么我不能得到 error.code equals 'auth/argument-error' 就像我对其他 'auth/something-error' 错误代码所做的那样?

eg When I have a login form and press button without fill email and password, the following error in console is thrown:例如,当我有一个登录表单并按下没有填写 email 和密码的按钮时,会在控制台中抛出以下错误:

在此处输入图像描述

How can I get this error object and save in a variable?我怎样才能得到这个错误 object 并保存在一个变量中?

@Frank van Puffelen, please, answer it. @Frank van Puffelen,请回答。

signin.js登录.js

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();
                });
        });
    };

This happens when email or password is not provided to firebase and cant be handled in catch block.当 email 或密码未提供给 firebase 且无法在 catch 块中处理时,会发生这种情况。 as it is an argument error.因为它是一个参数错误。 below is code that checks if email and password is present and then only calls the firebase.auth()下面是检查 email 和密码是否存在的代码,然后只调用 firebase.auth()

$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);

    });


};

You need to have an div or button or any element that has the ID specified on the new RecaptchaVerifier constructor.您需要有一个 div 或按钮或任何具有在新的 RecaptchaVerifier 构造函数中指定的 ID 的元素。 Please have a look at the code below请看下面的代码

window.recaptchaVerifier = new RecaptchaVerifier("sign-in-button", {
  'callback': (response) => {
    console.log("prepared phone auth process");
  }
}, auth);

I think this is a problem with the RecaptchaVerifier我认为这是 RecaptchaVerifier 的问题

In my case, I had to add the Dependecies in initializeAuth function, to use the Providers and Email & Password .在我的例子中,我必须在initializeAuth function 中添加Dependecies ,以使用ProvidersEmail & Password

export const auth = () => initializeAuth(app(), {
  persistence: browserSessionPersistence,
  popupRedirectResolver: browserPopupRedirectResolver,
});

If you need more details, I found my solution here如果您需要更多详细信息,我在这里找到了我的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 SMS Firebase 进行身份验证:错误(身份验证/参数错误) - Auth with SMS Firebase: Error (auth/argument-error) 使用 next-firebase-auth 获取 auth/argument-error - get auth/argument-error with next-firebase-auth Firebase 使用 Typescript 的双因素身份验证:错误(auth/argument-error) - Firebase Two-Factor Authentication with Typescript: Error (auth/argument-error) 尝试使用 Google/Facebook 登录时出现 Firebase 错误“auth/argument-error” - Firebase error "auth/argument-error" when trying to sign in with Google/Facebook 如何处理 flutter 中的 firebase 身份验证异常? - how to handle firebase auth exceptions in flutter? 如何处理 Firebase flutter 上的 Auth 异常 - How to Handle Firebase Auth exceptions on flutter 如何处理 Firebase flutter 上的 Auth 异常 - How to Handle Firebase Auth exceptions on flutter 如何处理 Firebase Auth account-exists-with-different-credential 错误 - How to handle Firebase Auth account-exists-with-different-credential Errors 错误:配置项目“:firebase_auth_web”时出现问题 - Error: A problem occurred configuring project ':firebase_auth_web' Firebase 错误:来自 APNS 或 Web 推送服务的身份验证错误 - Firebase Error: Auth error from APNS or Web Push Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM