-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[firebase_auth] linkWithCredential uses current user instead of user object on which the function is called #48
Comments
After digging the source code, I realized that the plugin always uses the currentUser linked to the FirebaseApp. This is far from ideal, and a call on a method of a FirebaseUser should not use the currentUser but the user on which the method has been called. AuthResult authResult;
final FirebaseUser previousUser = await FirebaseAuth.instance.currentUser();
final firebaseAppTemp = await FirebaseApp.configure(name: 'temporaryApp', options: await FirebaseAuth.instance.app.options);
final FirebaseAuth firebaseAuthTemp = FirebaseAuth.fromApp(firebaseAppTemp);
final Firestore firestoreTemp = Firestore(app: firebaseAppTemp);
try {
authResult = await currentUser.linkWithCredential(credential);
} on PlatformException catch (err) {
if (err.code == 'ERROR_CREDENTIAL_ALREADY_IN_USE') {
// Signin to the existing account
authResult = await firebaseAuthTemp.signInWithCredential(credential);
// TODO : Data migration - NOW USING 'firestoreTemp'
// 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 - NOW USING 'firestoreTemp'
} else {
throw err;
}
} |
Unfortunately this isn't possible since Dart vs Native code can't keep track of different user instances. That being said, work is being done to pass back an updated credential via the error as expected. |
Hey 👋 Our rework of the Please could you update to the new version. If you have any problems with the updated plugins please raise a new GitHub issue. For help migrating to the new plugins please see the new migration guide: https://firebase.flutter.dev/docs/migration |
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:
Ugly code:
Sadly, calling
previousUser.linkWithCredential()
seems to usefirebaseAuth.getCurrentUser()
and not the user on which the call has been done, resulting into anUSER_REQUIRED
error.See
FirebaseAuthPlugin.java:275
The text was updated successfully, but these errors were encountered: