Skip to content

Commit

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

This fixes an issue with Apple sign on Android. iOS was fixed with this commit. iOS was fixed with this PR #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 c6f4699 commit 6a8f8ad
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

1 comment on commit 6a8f8ad

@vercel
Copy link

@vercel vercel bot commented on 6a8f8ad Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.