首页 > 解决方案 > 如何使用 Flutter 在 Firebase 中正确登录和注册?

问题描述

我有这个应用程序可以通过firebase +电子邮件验证进行登录和注册,但当用户输入用户名,电子邮件,密码时,效率不是很高,......即使电子邮件错误,它也会注册所以我搜索并在firebase中找到了一个电子邮件验证的解决方案,但问题是如果用户没有验证,Firebase会注册它并且他可以登录(即使电子邮件无效),所以有什么想法吗?也是新手。我在注册页面中执行的注册代码:

static Future signup(String email, String password, BuildContext ctx) async {
    String emessage;
    if (email == '' || password == '') {
      emessage = 'Please Provide Valid Email And Password';
    } else {
      emessage = 'An Error Occurred. Please Try Again Later.';
    }
    try {
      final FirebaseUser user = (await _auth.createUserWithEmailAndPassword(
        email: email,
        password: password,
      ))
          .user;
      user.sendEmailVerification();
      return user.uid;
    } catch (e) {
      showDialog(
          context: ctx,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text('Error'),
              content: Text(emessage),
              actions: [
                FlatButton(
                  onPressed: () => Navigator.pop(context),
                  child: Text('Ok'),
                ),
              ],
            );
          });
    }
  }

标签: firebaseflutterdartfirebase-authenticationemail-verification

解决方案


Firebase 文档没有createUserWithEmailAndPassword列出任何强制预先电子邮件验证的参数。

你可以

  1. 首次登录后使用signInWithEmailLink并添加密码。
  2. 禁止没有经过验证的电子邮件地址的用户访问您应用中的内容——就像您对未经验证的用户执行此操作一样。

推荐阅读