From 62d684fa896f6f204cf6b6fb3042b8c202b7bddf Mon Sep 17 00:00:00 2001 From: Neal Manaktola Date: Fri, 30 Oct 2020 14:31:42 -0400 Subject: [PATCH] bug(auth): fixed issue with apple sign-in on android This fixes an issue with Apple sign on Android. iOS was fixed with this commit. iOS was fixed with this PR https://github.com/invertase/react-native-firebase/pull/4359. Note the solution is different. On iOS, it looks like we bubble the auth credentials back to js land and then retry login. Here, we attempt another login on auth collision errors --- .../auth/ReactNativeFirebaseAuthModule.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java index 8977fa159b..90afe46fa6 100644 --- a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +++ b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java @@ -45,6 +45,7 @@ import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException; import com.google.firebase.auth.FirebaseAuthProvider; import com.google.firebase.auth.FirebaseAuthSettings; +import com.google.firebase.auth.FirebaseAuthUserCollisionException; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.auth.FirebaseUserMetadata; import com.google.firebase.auth.GetTokenResult; @@ -1303,9 +1304,20 @@ private void linkWithCredential( } else { Exception exception = task.getException(); Log.e(TAG, "link:onComplete:failure", exception); - promiseRejectAuthException(promise, exception); - } - }); + if (exception instanceof FirebaseAuthUserCollisionException) { + FirebaseAuthUserCollisionException authUserCollisionException = (FirebaseAuthUserCollisionException) exception; + AuthCredential updatedCredential = authUserCollisionException.getUpdatedCredential(); + firebaseAuth.signInWithCredential(updatedCredential).addOnCompleteListener(getExecutor(), result -> { + if (result.isSuccessful()) { + promiseWithAuthResult(result.getResult(), promise); + } else { + promiseRejectAuthException(promise, exception); + } + }); + } else { + promiseRejectAuthException(promise, exception); + } + }}); } else { promiseNoUser(promise, true); }