Skip to content

Commit

Permalink
fix(auth, android): if no credential in collision exception, avoid ac…
Browse files Browse the repository at this point in the history
…cessing it
  • Loading branch information
mikehardy committed May 15, 2024
1 parent bc14423 commit 384b915
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1617,17 +1617,19 @@ private void linkWithCredential(
promiseWithAuthResult(task.getResult(), promise);
} else {
Exception exception = task.getException();
if (exception instanceof FirebaseAuthUserCollisionException) {
FirebaseAuthUserCollisionException authUserCollisionException =
(FirebaseAuthUserCollisionException) exception;
AuthCredential updatedCredential =
authUserCollisionException.getUpdatedCredential();
Log.d(TAG, "link:onComplete:collisionFailure", exception);
promiseRejectLinkAuthException(promise, exception, updatedCredential);
} else {
Log.e(TAG, "link:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
if (exception instanceof FirebaseAuthUserCollisionException collEx) {
AuthCredential updatedCredential = collEx.getUpdatedCredential();
Log.d(TAG, "link:onComplete:collisionFailure", collEx);
// If we have a credential in the error, we can return it, otherwise fall
// through
if (updatedCredential != null) {
Log.d(TAG, "link:onComplete:collisionFailure had credential", collEx);
promiseRejectLinkAuthException(promise, collEx, updatedCredential);
return;
}
}
Log.e(TAG, "link:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
}
});
} else {
Expand Down Expand Up @@ -2239,7 +2241,9 @@ private void promiseRejectAuthException(Promise promise, Exception exception) {
* @param authCredential
*/
private void promiseRejectLinkAuthException(
Promise promise, Exception exception, AuthCredential authCredential) {
@NonNull Promise promise,
@NonNull Exception exception,
@NonNull AuthCredential authCredential) {
WritableMap error = getJSError(exception);
String authHashCode = String.valueOf(authCredential.hashCode());

Expand Down

0 comments on commit 384b915

Please sign in to comment.