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.
Create fictional phone numbers and verification codesIn the Firebase console, open the Authentication section. In the Sign in method tab, enable the Phone provider if you haven't already. Open the Phone numbers for testing accordion menu. Provide the phone number you want to test, for example: +1 650-555-3434.
Don't forget to go in Firebase Project Settings > App check > and Register firebase project in SafetyNet and Play Integrity register with default time token 1 hour and u will remove reCaptcha from phone auth OTP! That's awesome.
You are planning for two step authentication in app with phone and email. Please see this question and answer https://stackoverflow.com/a/44966449/7672400 . I've implemented the same. It might help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With