I am coding application on mvvm model and use firebase authentication, firestore.
I would like to ask how to implement them. because, Firebase auth and firestore functions are all asynchronous.
fun sendPasswordResetEmail() {
auth.sendPasswordResetEmail(emailAddress)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
isSendEmailSuccess.postValue(true)
} else {
isSendEmailSuccess.postValue(false)
}
}.addOnFailureListener {e ->
if(e is FirebaseAuthException)
isSendEmailSuccess.postValue(false)
}
}
example, here is the code that implements the forgot password functionality. and i am implementing it in the viewmodel. If code in repository, then how do i deploy it
I tried
suspend fun sendPasswordResetEmail(emailAddress: String) : Boolean {
var result = false
auth.sendPasswordResetEmail(emailAddress)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
result = true
} else {
result = false
}
}.addOnFailureListener {e ->
result = true
}.await()
return result
}
I tried to code like this in the repository, but the code looks a bit redundant when having to create a result variable and call await(). is there a better way