Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phone authentication creates new account and breaks link on firebase

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.

like image 585
vishal dharankar Avatar asked Dec 09 '18 16:12

vishal dharankar


People also ask

How do I add my phone number to Firebase authentication?

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.

How do I remove Captcha verification from Firebase phone auth using Android?

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.


1 Answers

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

like image 57
Ashish Pardhiye Avatar answered Oct 20 '22 05:10

Ashish Pardhiye