如何使用Flutter在Firebase AUTH中创建2个不同的用户组

问题描述:

我的应用程序提供两种类型的用户.我需要划分FirebaseAuth,这样一个用户无法访问另一用户的用户组,反之亦然.我找不到有效的解决方案.有什么建议吗?

My app provides two types of users. I need to divide FirebaseAuth thus one user cannot access to the user group of the other and vice versa. I can't find a valid solution to do that. Any suggestions?

目前在FirebaseAuth中创建用户,我正在使用以下方法:

at the moment to create User in FirebaseAuth i use this method:

RaisedButton(
        elevation: 10,
        onPressed: rememberMe ? () async {
          try {
            final newUser =
            await _auth.createUserWithEmailAndPassword(
                email: InUser.email, password: password);

但我不知道如何拆分组.

but I can't understand how to split the groups.

据我所知,在Firebase Auth中没有直接实现这种概念,但实际上有两个选择:

There is no such concept directly implemented in Firebase Auth as far I know, but you have essentially 2 options:

  • 作为该用户在Firebase身份验证令牌中的自定义声明

  • as a custom claim in the Firebase Authentication token for that user

在数据库中使用用户集合以及与您的用户相关联的文档.

in the database using a User collection with documents associated with your users.

您应该在受信任的环境(即Cloud Functions甚至手动)中设置角色,否则如果您不通过访问规则保护文档,任何人都可以更改自己的角色.

You should be setting the role from within a trusted environment (i.e. Cloud Functions or even manually) as otherwise anyone can change their own role if you do not secure your documents by access rules.

在这两个位置之一中进行设置后,您就可以在客户端代码中访问角色信息.

Once set in either of these locations, you can access the role information in your client-side code.

您可能需要看看: https://www.youtube.com/watch?v = oFlHzF5U-HA