I am linkning an email with phone authenticated user account on firebase as per code given. I am first creating a new user using phone sms authentication, after that trying to associate an email with this user since I want to also let user login using email. For email I am using email link verification. Linking takes place and I can see two authentication methods for a user in dashboard. Now when I logout and try to login using email link authentication firebase creates a new user and now I have two user one by phone and other by email.
val credential:AuthCredential = EmailAuthProvider.getCredential(email,link)
mAuth!!.currentUser?.linkWithCredential(credential)?.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
Log.d(TAG, "linkWithCredential:success")
val user = task.result?.user
} else {
Log.w(TAG, "linkWithCredential:failure", task.exception)
Toast.makeText(baseContext, "Authentication failed.",
Toast.LENGTH_SHORT).show()
}
}
I have been banging my head on Firebase documents since hours now but not clue why this is happening . Neither could I find any post related to this. Any pointers are appreciated.