From 0159ead9633963af2ced2b44f0ffbccfe95b64fd Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Sun, 15 Nov 2020 18:00:47 -0500 Subject: [PATCH] fix(auth, android): handle failure to upgrade anonymous user This is related to a #4487 - attempting to re-login with credential after anonymous user signs in with apple sign-in on android --- .../auth/ReactNativeFirebaseAuthModule.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java b/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java index ad0570e254..4c9beb9d78 100644 --- a/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +++ b/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java @@ -1314,13 +1314,18 @@ private void linkWithCredential( 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); - } - }); + try { + firebaseAuth.signInWithCredential(updatedCredential).addOnCompleteListener(getExecutor(), result -> { + if (result.isSuccessful()) { + promiseWithAuthResult(result.getResult(), promise); + } else { + promiseRejectAuthException(promise, exception); + } + }); + } catch (Exception e) { + // we the attempt to log in after the collision failed, reject back to JS + promiseRejectAuthException(promise, exception); + } } else { promiseRejectAuthException(promise, exception); }