Issue
I have a problem with my application. When logging in without email and password there is no localize Message appears and returns to the previous screen. How can I solve it?
this code for the login button:
login.setOnClickListener {
val email = etEmail.text.toString()
val pass = etPass.text.toString()
auth.signInWithEmailAndPassword(email, pass)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful && auth.currentUser!!.isEmailVerified) {
Toast.makeText(this,"Successful Login", Toast.LENGTH_SHORT).show();
}
else if (!auth.currentUser!!.isEmailVerified)
Toast.makeText(this,"Check your email", Toast.LENGTH_LONG).show();
else
Toast.makeText(this,"${task.exception?.localizedMessage}", Toast.LENGTH_LONG).show();
}
}
Solution
If you want to be able to sign in only if the fields, email, and password are not empty, then please use the following lines of code:
val email = etEmail.text.toString().trim()
val pass = etPass.text.toString().trim()
if(!TextUtils.isEmpty(email) && !TextUtils.isEmpty(pass)) {
auth.signInWithEmailAndPassword(email, pass).addOnCompleteListener(this) {
//Your code.
}
} else {
Log.d("TAG", "email or pass empty.")
}
Answered By - Alex Mamo
Answer Checked By - Timothy Miller (JavaFixing Admin)