Skip to content

Commit

Permalink
fix(auth, android): fixed user collision handling with apple sign-in (i…
Browse files Browse the repository at this point in the history
…nvertase#4487)

This fixes an issue with Apple sign on Android. iOS was fixed with this commit. iOS was fixed with this PR invertase#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
  • Loading branch information
nealmanaktola authored Nov 10, 2020
1 parent ba5eca2 commit fffdcee
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fffdcee

Please sign in to comment.