Skip to content
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

Update User Success Notice Bug #21

Closed
HussainON opened this issue May 22, 2021 · 4 comments
Closed

Update User Success Notice Bug #21

HussainON opened this issue May 22, 2021 · 4 comments

Comments

@HussainON
Copy link

When you update your email with an email that already exists in the database, you get an update user success notice even though the update should fail and the snack bar notice should be "Email is already in use" or something like that.

@delay
Copy link
Owner

delay commented May 23, 2021

So while you can't actually update to an already existing email to the same address, the firebase api doesn't handle this error correctly and pass it through to us for handling. You can see it has an error message from the command line. However the method channel doesn't get handled and passed along by the firebase_auth api.
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: [firebase_auth/email-already-in-use] The email address is already in use by another account. #0 MethodChannelUser.updateEmail (package:firebase_auth_platform_interface/src/method_channel/method_channel_user.dart:195:7)

Not sure how to fix this at this point without writing a whole bunch of extra code that would try and login with the new email address to see if it exists and then run through the update email function. I don't plan to do that as it would be better for flutter firebase_auth to pass along the error message.

If anyone knows a good way to handle this problem, please let me know otherwise I will close this issue out until the package is updated and correctly handles the error. You may want to pass this problem to the firebase_auth package.

@delay
Copy link
Owner

delay commented May 23, 2021

It probably would need to be reported here. firebase/flutterfire#2582

@delay delay closed this as completed May 28, 2021
@tezcane
Copy link

tezcane commented Feb 22, 2022

I was able to fix it inline with 3 small changes. There is a threading issue. So the error is happening asynchronous to this code so it can't be caught:

         await _auth
            .signInWithEmailAndPassword(email: oldEmail, password: password)
            .then((_firebaseUser) async { // 1. add async here
          await _firebaseUser.user!  // 2. add await here
              .updateEmail(user.email)
              .then((value) => _updateUserFirestore(user, _firebaseUser.user!));
        });
      } catch (err) {
        //not yet working, see this issue https://github.com/delay/flutter_starter/issues/21 (lolz)
        if (err.toString() ==  // 3. I had to modify this if logic too, at least with my firestore lib version.
            "[firebase_auth/email-already-in-use] The email address is already in use by another account.") {
          _authUpdateUserNoticeTitle = 'auth.updateUserEmailInUse'.tr;
          _authUpdateUserNotice = 'auth.updateUserEmailInUse'.tr;
        } else {

@delay delay reopened this Feb 22, 2022
delay added a commit that referenced this issue Feb 22, 2022
@delay
Copy link
Owner

delay commented Feb 22, 2022

Thanks so much! I have updated the project.

@delay delay closed this as completed Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants