【问题标题】:FirebaseAuth Disabled Users check and signout?FirebaseAuth 禁用用户检查和注销?
【发布时间】:2020-05-21 12:46:11
【问题描述】:

所以我有一个 onAuthStateChanged 流,我想检查用户是否已被管理员在 firebase 控制台上禁用以注销用户并再次进入登录页面,这是我的流检查用户是否已登录,但是如何检查用户是否被 firebase 控制台禁用:\
这是我的流的简单代码:

    return StreamBuilder<FirebaseUser>(
      stream: FirebaseAuth.instance.onAuthStateChanged,
      builder: (BuildContext context , snapshot){


        if (snapshot.connectionState == ConnectionState.active) {
              FirebaseUser user = snapshot.data;
              if (user == null) {
                return RegisterUi();
              }
              ;
            } else {
return HomePage()
    }

    }
    );

【问题讨论】:

    标签: firebase flutter dart firebase-authentication


    【解决方案1】:

    FirebaseAuth.instance.onAuthStateChanged 已弃用。 您应该使用authStateChangesuserChanges

    不幸的是,当用户被禁用时,它们都不会发出值。

    您可以尝试重新加载用户数据

    FirebaseAuth.instance.currentUser.reload();
    

    如果用户被禁用,它会抛出一个FirebaseAuthException e e.code'user-disabled'

    一些未经测试的代码:

    try {
          await FirebaseAuth.instance.currentUser.reload();
        } on FirebaseAuthException catch (e) {
          if (e.code == 'user-disabled') {
             // User is disabled.
          }
        }
    

    在您的示例中,如果您 reload(),则流将发出 null 并且 RegisterUi() 小部件将从构建器返回。

    【讨论】:

      猜你喜欢
      • 2017-12-12
      • 2019-03-05
      • 2022-10-15
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 2012-01-13
      • 1970-01-01
      相关资源
      最近更新 更多