dart 只有在电子邮件验证成功的情况下,才能在Firebase中创建用户帐户吗?[重复]

v8wbuo2f  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(115)

此问题在此处已有答案

Firebase Auth - createUserWithEmailAndPassword() - prevent login until email is verified(3个答案)
Is it Possible? sending email verification before a record is created in firebase authentication? [duplicate](2个答案)
Verify a user's email address before confirming registration, with Flutter and Firebase(1个答案)
27天前关闭。
通常,在Flutter中使用UserCredential userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword( email: email, password: password, );创建帐户后,电子邮件验证已发送给用户。“
我想知道:是否有可能在Firebase中创建一个用户帐户,只有在验证成功的情况下?

mklgxw1f

mklgxw1f1#

你描述的方式是不可能的。一旦你运行createUserWithEmailAndPassword,该帐户就被创建了。
你可以做的是使用Firebase Admin SDK写一些代码来定期删除那些在一段时间内没有验证过的帐户。也许你可以使用scheduled function每天运行这种过程。你不应该依赖于在客户端应用程序中运行这个逻辑,因为你不能保证它在帐户创建后会继续运行。
还可以考虑使用email link来创建用户帐户,因为您可以在一次调用中将帐户的创建与电子邮件验证捆绑在一起。

4xy9mtcn

4xy9mtcn2#

是的,有可能。

Future<void> registerUser(String email, String password) async {
  try {
    UserCredential userCredential = await FirebaseAuth.instance
        .createUserWithEmailAndPassword(email: email, password: password);

    // Send email verification
    await userCredential.user.sendEmailVerification();

    // Check if the email is verified before allowing further actions
    if (!userCredential.user.emailVerified) {
      // Handle the case where email verification is pending
      // You might log the user out and ask them to verify their email before signing in again
    } else {
      // Continue with your app flow for a verified user
      // For example, you might automatically sign in the user here
    }
  } catch (e) {
    // Handle any registration errors here
    print("Error registering user: $e");
  }
}

字符串
请同时检查thisthis

相关问题