我正在使用Firebase的电子邮件/密码身份验证。然后我处理异常消息。 和我首先注册,然后进入登录活动,但是当我写电子邮件时就注册了它。.我无法登录并收到此错误“该电子邮件地址已被另一个帐户使用”。
在Firebase面板中,我有注册的电子邮件,但是我无法登录。
这也是我的代码...首先已注册:
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()
}
}
}
答案 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();
}
}
});
}