[英]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.