使用电子邮件和密码firebase登录时,指定null或空字符串

时间:2017-05-23 10:10:01

标签: android firebase firebase-authentication

我想检查电子邮件是否已经过验证,我尝试使用AuthStateListener但是没有用,所以我尝试这样做 -

Intent intent=getIntent();
      email =intent.getStringExtra("email");
      password = intent.getStringExtra("password");
 auth = FirebaseAuth.getInstance();
    confirm = (Button) findViewById(R.id.confirmbtn);
    confirm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("e",email+""+password);
            auth.signInWithEmailAndPassword(email,password).
                    addOnCompleteListener(ConfirmActivity.this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if(task.isSuccessful())
                            {
                                checkIfEmailVerified(email,password);
                            }
                            else
                            {
                                Toast.makeText(ConfirmActivity.this, "failed to sign in", Toast.LENGTH_SHORT).show();

                            }

                        }
                    });

        }
    });

但是当点击此行的确认按钮时第一次返回不幸的错误

auth.signInWithEmailAndPassword(email,password).

异常:

  E/AndroidRuntime: FATAL EXCEPTION: main
              Process: iti.signinsignupfirebase, PID: 4108
              java.lang.IllegalArgumentException: Given String is empty or null
                  at        com.google.android.gms.common.internal.zzac.zzdr(Unknown Source)
                  at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source)
                  at iti.signinsignupfirebase.ConfirmActivity$1.onClick(ConfirmActivity.java:54)
                  at android.view.View.performClick(View.java:4508)
                  at android.view.View$PerformClick.run(View.java:18675)
                  at android.os.Handler.handleCallback(Handler.java:733)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5584)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
                  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

在firebase当前版本中存在一个错误,因此我们需要首先注销用户,否则验证var将始终显示为false。这是您可以做的一个技巧,当您第一次注册用户时,向该用户发送验证电子邮件,然后注销该用户并显示登录屏幕。  之后,如果用户登录检查电子邮件验证,如果他/她验证,则转到主要活动。