该电子邮件地址已被另一个帐户使用(使用电子邮件身份验证/密码Firebase)

时间:2018-12-16 11:24:14

标签: android kotlin firebase-authentication

我正在使用Firebase的电子邮件/密码身份验证。然后我处理异常消息。 和我首先注册,然后进入登录活动,但是当我写电子邮件时就注册了它。.我无法登录并收到此错误“该电子邮件地址已被另一个帐户使用”。

在Firebase面板中,我有注册的电子邮件,但是我无法登录。

enter image description here

这也是我的代码...首先已注册

  private lateinit var firebaseAuth: FirebaseAuth

    /*Firebase Auth*/
        firebaseAuth = FirebaseAuth.getInstance()

/*Register With Firebase Auth*/
        fun onRegisterBtnClick(view: View) {



            val dialog: ProgressDialog = ProgressDialog.show(
                this@StudentRegisterActivity, getString(R.string.please_wait),
                getString(R.string.processing), true
            )

            firebaseAuth.createUserWithEmailAndPassword(stuEmail, stuPass).addOnCompleteListener {
                dialog.dismiss()
                if (it.isSuccessful) {
                    val snackbar: Snackbar = Snackbar.make(
                        binding.coordinator,
                        getString(R.string.register_succesed), Snackbar.LENGTH_SHORT
                    )
                    snackbar.show()


                    /*Intent to Login Activity*/
                    val intent = Intent(this@StudentRegisterActivity, StudentLoginActivity::class.java)

                    startActivity(intent)

                } else {
                    Log.e(TAG, it.exception.toString())
                    val snackbar: Snackbar = Snackbar.make(
                        binding.coordinator,
                        it.exception!!.message!!, Snackbar.LENGTH_SHORT
                    )
                    snackbar.show()
                }
            }


        }

登录

    private lateinit var firebaseAuth: FirebaseAuth


        /*Firebase Auth*/
        firebaseAuth = FirebaseAuth.getInstance()

  fun onLoginBtnClick(view: View) {

            val dialog: ProgressDialog = ProgressDialog.show(
                this@StudentLoginActivity, getString(R.string.please_wait),
                getString(R.string.processing), true
            )

            firebaseAuth.createUserWithEmailAndPassword(stuEmail, stuPass).addOnCompleteListener {
                dialog.dismiss()
                if (it.isSuccessful) {
                    val snackbar: Snackbar = Snackbar.make(
                        binding.coordinator,
                        getString(R.string.register_succesed), Snackbar.LENGTH_SHORT
                    )
                    snackbar.show()

                    /*Intent to Login Activity*/
                    val intent = Intent(applicationContext, BatchesStudentActivity::class.java)
                    startActivity(intent)

                } else {
                    Log.e(TAG, it.exception.toString())
                    val snackbar: Snackbar = Snackbar.make(
                        binding.coordinator,
                        it.exception!!.message!!, Snackbar.LENGTH_SHORT
                    )
                    snackbar.show()
                }
            }


        }

1 个答案:

答案 0 :(得分:3)

在您的clickListener中执行此操作

            if(!TextUtils.isEmpty(stuEmail) && !TextUtils.isEmpty(stuPass)){


                firebaseAuth.signInWithEmailAndPassword(stuEmail, stuPass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        if(task.isSuccessful()){

                            //give the intent or whatever you want

                        } else {

                            String errorMessage = task.getException().getMessage();
                            Toast.makeText(LoginActivity.this, "Error : " + errorMessage, Toast.LENGTH_LONG).show();


                        }



                    }
                });

            }