<code> override suspend fun signIn(email: String, password: String): Flow<Response<Boolean>> =
callbackFlow {
try {
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
trySend(Response.Success(true))
val user = auth.currentUser
}
else{
try {
throw task.exception!!
}
catch (e: FirebaseAuthInvalidCredentialsException){
trySend(Response.Failure(e))
}
}
}
trySend(Response.Loading)
}
catch (e:Exception){
trySend(Response.Failure(e))
}
awaitClose { }
}
</code>
<code> override suspend fun signIn(email: String, password: String): Flow<Response<Boolean>> =
callbackFlow {
try {
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
trySend(Response.Success(true))
val user = auth.currentUser
}
else{
try {
throw task.exception!!
}
catch (e: FirebaseAuthInvalidCredentialsException){
trySend(Response.Failure(e))
}
}
}
trySend(Response.Loading)
}
catch (e:Exception){
trySend(Response.Failure(e))
}
awaitClose { }
}
</code>
override suspend fun signIn(email: String, password: String): Flow<Response<Boolean>> =
callbackFlow {
try {
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
trySend(Response.Success(true))
val user = auth.currentUser
}
else{
try {
throw task.exception!!
}
catch (e: FirebaseAuthInvalidCredentialsException){
trySend(Response.Failure(e))
}
}
}
trySend(Response.Loading)
}
catch (e:Exception){
trySend(Response.Failure(e))
}
awaitClose { }
}
I want to handle cases of user does not exist and wrong password , firebase is throwing same exception in both cases so how to differentiate both cases and let the user know why sign in got failed?
<code>Initial task failed for action RecaptchaAction(action=signInWithPassword)with exception - The supplied auth credential is incorrect, malformed or has expired
</code>
<code>Initial task failed for action RecaptchaAction(action=signInWithPassword)with exception - The supplied auth credential is incorrect, malformed or has expired
</code>
Initial task failed for action RecaptchaAction(action=signInWithPassword)with exception - The supplied auth credential is incorrect, malformed or has expired