firebase-android-sdk
firebase-android-sdk copied to clipboard
`linkWithCredential()` produces "email-already-in-use" exception now when linking EmailAuthProvider with same email address
[READ] Step 1: Are you in the right place?
Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:
- For general technical questions, post a question on StackOverflow with the firebase tag.
- For general Firebase discussion, use the firebase-talk google group.
- For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.
[REQUIRED] Step 2: Describe your environment
- Android Studio version: 2022.3.1
- Firebase Component: Auth (Database, Firestore, Storage, Functions, etc)
- Component version: 22.3.0
[REQUIRED] Step 3: Describe the problem
Since firebase-android-sdk BOM 32.5.0 the behaviour of linkWithCredential()
has changed, you now get an "email-already-in-use" exception when trying to link an EmailAuthProvider with an existing user with the same email address. I think this might be a breaking change.
This bug was first report on the FlutterFire repo: https://github.com/firebase/flutterfire/issues/12156
Steps to reproduce:
Below is the code for reproduction. A few things to remember:
-
The google authentication should have the same email address as the one you use in the
EmailAuthProvider
. the aim is to link the accounts like below: -
This setting in your Firebase console should be set:
Relevant Code:
I have a full reproduction on this branch (it was hacked together for a repro 😓) : https://github.com/russellwheatley/android-storage-emulator/tree/auth-linkWithCredential
For the above, you would have to update:
- Use your own Firebase project (i.e replace the
google-services.json
). - You will also need to change the client id in the strings.xml here: https://github.com/russellwheatley/android-storage-emulator/blob/auth-linkWithCredential/app/src/main/res/values/strings.xml#L9
- Also ensure your app has the SHA-1 key in the Firebase console.
- Run the app and press the button in the bottom right hand corner.
Alternatively, below is a snippet of the code that is the issue if you wish to drop it in your own project:
FirebaseApp app = FirebaseApp.getInstance();
FirebaseAuth mAuth = FirebaseAuth.getInstance(app);
// You will have to generate your own "idToken"
AuthCredential firebaseCredential = GoogleAuthProvider.getCredential(idToken, null);
mAuth.signInWithCredential(firebaseCredential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
AuthCredential credential = EmailAuthProvider.getCredential("[email protected]", "some-password");
assert user != null;
user.linkWithCredential(credential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "onComplete: LINKED");
} else {
Log.d(TAG, "onComplete: " + Objects.requireNonNull(task.getException()).getMessage());
}
}
});
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
}
}
});
Hi @russellwheatley, thank you for reaching out and reporting the issue. I was able to reproduce the issue with the MCVE you shared. Thank you for that.
Just to share my findings, this issue seems to exists in version 22.3.0 and above. Per checking in version 22.2.0, linkWithCredential()
is working as intended.
I’ll notify our engineers and see what we can do here.
The same problem is happening with Flutter
Thank you for reporting! As mentioned in the iOS bug, we will update here when the fix is released.
+1 We are having the same problem. Downgraded to SDK 10.17.0 temporally. Please let us know when there's any update. Thank you!
Same problem here +1
The fix was released. Please let us know if it works for you. Thanks!
I have tested this on FlutterFire, and it is working now 😄. Thank you for the fix!
Thank you for confirming @russellwheatley. I'll be closing this thread now. Let us know if we need to reopen the issue. Thanks!.