如何检查电子邮件是否已在Firebase中使用?

时间:2020-04-19 14:47:40

标签: java android firebase firebase-authentication

我正在使用Firebase Cloud Firestore。我在注册活动中编写了以下代码:

import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.FirebaseFirestore;

mAuth.createUserWithEmailAndPassword(users_email, users_password)
    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            try {
                if (task.isSuccessful()) {
                    Log.d(this.getClass().getName(), "createUserWithEmail:success");
                    addNewUser(users_email);
                    finish();
                } else {
                    Log.w(this.getClass().getName(), "createUserWithEmail:failure",
                            task.getException());
                    Toast.makeText(getApplicationContext(), R.string.failed_to_register,
                            Toast.LENGTH_SHORT).show();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

效果很好。如果用户输入了已被使用的电子邮件,则它将无法使用。但是,如果用户输入了电子邮件,并使用了与电子邮件相同的密码,它将登录。这不是我想要的行为。如何检查电子邮件是否已经使用过并且在这种情况下失败?

0 个答案:

没有答案