FirebaseAuth禁用的用户检查并注销? [英] FirebaseAuth Disabled Users check and signout?

查看:24
本文介绍了FirebaseAuth禁用的用户检查并注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

so i am having a stream of onAuthStateChanged and i want check if the user has been disabled by the administrator on firebase console to logout the user and go to login page again , here is my stream checking if the user is loged or not , but how to check if the user disabled by firebase console :\
here is a simple code of my stream :

    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()
    }

    }
    );

推荐答案

FirebaseAuth.instance.onAuthStateChanged 已弃用.您应该使用 authStateChanges userChanges .

FirebaseAuth.instance.onAuthStateChanged is deprecated. You should use either authStateChanges or userChanges.

不幸的是,当用户被禁用时,它们都不发出任何值.

Unfortunately none of them emits values when the user gets disabled.

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

You can attempt to reload the user data with

FirebaseAuth.instance.currentUser.reload();

如果用户被禁用,它将抛出 FirebaseAuthException e ,其中 e.code 'user-disabled'.

If the user is disabled, it will throw a FirebaseAuthException e where e.code is 'user-disabled'.

一些未经测试的代码:

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

在您的示例中,如果您 reload(),则流将发出 null ,并且 RegisterUi()小部件将从建造者.

In your example, if you reload(), the stream will emit null and the RegisterUi() widget will be returned from the builder.

这篇关于FirebaseAuth禁用的用户检查并注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆