Monday, 7 October 2019

Firebase Auth - GoogleAuthProvider and FacebookAuthProvider is replacing EmailAuthProvider

Steps

  • Create user with createUserWithEmailAndPassword
  • auth.signOut()
  • User signInWithCredential using FacebookAuthProvider or GoogleAuthProvider with the same e-mail used in createUserWithEmailAndPassword
  • It`s throw FirebaseAuthUserCollisionException (But this is not happening, instead signInWithCredential is successfull and replace the provider by Facebook or Google

The documentation is below

https://developers.google.com/android/reference/com/google/firebase/auth/FirebaseAuth.html#signInWithCredential(com.google.firebase.auth.AuthCredential)

Code

Create user

auth.createUserWithEmailAndPassword(email, password)
    .addOnSuccessListener {
        callBack.invoke(FirebaseAuthResult.Success)
    }.addOnFailureListener {
        val authResult = it.factoryExceptionAuthResult()
        callBack.invoke(authResult)
    }

signInWithCredential

auth.signInWithCredential(authCredential)
    .addOnSuccessListener {
       callBack.invoke(FirebaseAuthResult.Success)
    }.addOnFailureListener {
       val authResult = it.factoryExceptionAuthResult()
       callBack.invoke(authResult)
    }

Libs

implementation 'com.facebook.android:facebook-login:[5,6)'
implementation 'com.google.firebase:firebase-auth:19.1.0' 
implementation 'com.google.android.gms:play-services-auth:17.0.0'


from Firebase Auth - GoogleAuthProvider and FacebookAuthProvider is replacing EmailAuthProvider

No comments:

Post a Comment