简体   繁体   English

Flutter FirebaseAuth:当 email 地址被其他用户使用时,SignUp 无法处理错误

[英]Flutter FirebaseAuth: SignUp unable to handle error when the email address is used by another user

My code here, and the error pointed at -> await FirebaseAuth.instance.createUserWithEmailAndPassword( email: email.trim(), password: password.trim());我的代码在这里,错误指向-> await FirebaseAuth.instance.createUserWithEmailAndPassword( email: email.trim(), password: password.trim()); - in code below - 在下面的代码中

 Future SignUp() async {
    try {
      UserCredential result = await FirebaseAuth.instance
          .createUserWithEmailAndPassword(
              email: email.trim(), password: password.trim());
      User user = result.user;
      return user;
    } on FirebaseAuthException catch (e) {
      print(e);
      if (e.code == 'email-already-in-use') {
        setState(
            () // setState rebuilds the entire build by modifying the code inside it
            {
          error = e.toString();
          EmailExists =
              true; //sets the emailExists variable to 'true' and rebuild
        });
      }
    }
  }

Error: PlatformException (PlatformException(firebase_auth, com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account., {message: The email address is already in use by another account., additionalData: {}, code: email-already-in-use}, null)) Error: PlatformException (PlatformException(firebase_auth, com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account., {message: The email address is already in use by another account., additionalData: {},代码:电子邮件已在使用},空))

Try a different email because you already created a user with the email and password尝试不同的 email 因为您已经使用 email 和密码创建了一个用户

By default Firebase Authentication only allows a single user to register with a specific email address in a project.默认情况下 Firebase 身份验证仅允许单个用户在项目中使用特定的 email 地址进行注册。 When a second user tries to register with the same email address, you get the error that you have and you'll need to handle that scenario in your code.当第二个用户尝试使用相同的 email 地址注册时,您会收到错误,您需要在代码中处理该场景。 Typically you'll tell the user that the email address has already been registered and either ask them for their password, or tell them to use another email address.通常,您会告诉用户 email 地址已经注册,然后询问他们的密码,或者告诉他们使用另一个 email 地址。

If you want to allow multiple users to register with the same email address, you can enable that by changing the Multiple accounts per email address setting in the Sign-in methods pabel of the Firebase console.如果您希望允许多个用户使用相同的 email 地址注册,您可以通过在 Z035489FF8D092741949ZE4A83241F 控制台的登录方法选项卡中更改每个 email 地址的多个帐户设置来启用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取当前用户的电子邮件地址 FirebaseAuth/Flutter - How to get current user email address FirebaseAuth/Flutter Flutter Firebaseauth 异常错误“电子邮件格式错误” - Flutter Firebaseauth exception Error “Email is badly formatted” FLutter FirebaseAuth Email 验证 - FLutter FirebaseAuth Email verification 用户注册(Angularjs和Firebase)时,如何检查电子邮件地址是否存在 - How do i check if an email address exists when user signup (Angularjs and Firebase) 创建FirebaseAuth实例时出现错误,请使用电子邮件和密码创建并登录 - Receiving error when creating FirebaseAuth instance create & sign in with email and password Flutter:在 firebaseAuth 错误时显示小吃吧 - Flutter: Show snackbar on firebaseAuth error 让一个用户使用 firebase/flutter 中的自定义字段注册另一个用户 - Have one user signup another user with custom fields in firebase/flutter 我可以使用 sharedPreference 代替 FirebaseAuth.instance.currentUser.email Flutter 来获取当前用户数据吗 - can I use sharedPreference to get current user data instead of FirebaseAuth.instance.currentUser.email Flutter FirebaseAuth-复制修改的用户登录名/电子邮件 - FirebaseAuth - Replication of a modifed user login/email 在 Flutter 中使用 FirebaseAuth 检查用户的身份验证状态 - check authentication state of User using FirebaseAuth in Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM