-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
blocked: customer-responseWaiting for customer response, e.g. more information was requested.Waiting for customer response, e.g. more information was requested.impact: customerA bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)plugin: authresolution: needs-reproThis issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.type: bugSomething isn't workingSomething isn't working
Description
I'm trying to manage the 'ERROR_CREDENTIAL_ALREADY_IN_USE' error when linking an account to another, by following the android guide: https://firebase.google.com/docs/auth/web/account-linking#link-email-address-and-password-credentials-to-a-user-account
In the last code section, when the credentials are already in use:
- User logged in with account [A], and submitted credentials [C]
- SignIn on the already existing account [B] with credentials [C]
- Retrieve app's data linked to account [B]
- Delete the existing account [B]
- Link user account [A] to the credentials [C] and SignIn with credentials [C]
- Import data of account [B] on the linked user
Ugly code:
AuthResult authResult;
final FirebaseUser previousUser = await FirebaseAuth.instance.currentUser();
try {
authResult = await previousUser.linkWithCredential(credential);
} on PlatformException catch (err) {
if (err.code == 'ERROR_CREDENTIAL_ALREADY_IN_USE') {
// Signin to the existing account
authResult = await FirebaseAuth.instance.signInWithCredential(credential);
// TODO : Get data from the authResult.user account
// Delete existing account
// TODO : better deletion error management
await authResult.user.delete();
// Link previous user
authResult = await previousUser.linkWithCredential(credential);
// TODO : merge previous account data to current account
} else {
throw err;
}
}Sadly, calling previousUser.linkWithCredential() seems to use firebaseAuth.getCurrentUser() and not the user on which the call has been done, resulting into an USER_REQUIRED error.
See FirebaseAuthPlugin.java:275
jans-y and gurmukhp
Metadata
Metadata
Assignees
Labels
blocked: customer-responseWaiting for customer response, e.g. more information was requested.Waiting for customer response, e.g. more information was requested.impact: customerA bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)plugin: authresolution: needs-reproThis issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.type: bugSomething isn't workingSomething isn't working