如何在Firebase中创建不同的用户组? [英] How to create different user groups in Firebase?

查看:189
本文介绍了如何在Firebase中创建不同的用户组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode制作销售点应用程序.

I am making a point of sale app, using Xcode.

我希望该应用程序跟踪库存商品,允许用户使用条形码搜索库存,扫描库存,添加或查找库存.库存项目将存储在用户的商店"中.

I want this app to keep track of stock items, allow users to search stock, scan stock, add or lookup stock using a barcode. Items of stock will be stored in a users 'store'.

我想拥有三种类型的用户:

I want to have three types of users:

  1. 经理用户,他创建商店并拥有对该商店的完全访问权限.他可以管理所有雇员用户",例如删除他们的访问权限,并且必须由他邀请雇员用户使用唯一的代码加入其商店.他将具有员工用户"所不具备的特定能力,例如添加和编辑股票的能力.
    经理帐户的外观

  1. A manager user, who creates a store and has full access to the store. He can manage all of the 'employee users', such as deleting their access and employee users must be invited by him to join his store using a unique code. He will have specific abilities that 'employee users' do not such as the ability to add and edit stock.
    What a manager account would look like

有限制的员工用户. (例如,无法看到编辑用户"页面,并且不能选择编辑经理用户拥有的库存).
员工帐户的外观

A employee user, who has limitations. (e.g. cannot see edit users page and not option to edit stock that manager user has).
What a Employee account would look like

购物者用户,他只能看到商店和商店中的物品. 购物者用户帐户的外观

A shopper user who can only see a store and the items in a store. What a shopper users account would look like

随附的UI设计应显示我的意思.如您所见,经理用户具有一个管理员工"选项卡,我希望只有他可以拥有,其他用户则不需要.在查看库存时,经理还可以选择获取更多详细信息,而员工用户则没有.购物者帐户只能访问两个功能,即查找商店和检查商店中的库存.

The attached UI design should show what I mean. As you can see, the manager user has a manage employee tab that I wish only he can have and the other users do not. The manager has also got the option for more details when looking at stock, while the employee user does not. The shopper account has only got access to two functions, looking up a store, and checking the stock in a store.

所以我的问题是, 如何在Firebase中为我的应用编码三种不同类型的用户? &如何在只向其他用户显示其他选项的同时仅向他们显示我要显示的选项?

So my question is, How do I code three different types of users in Firebase for my app? & How do I show them only options that I want to show them while showing other options to other users?

推荐答案

这是一个非常广泛的主题,其中很多取决于您如何实现应用程序的各个部分.以下是许多可能的答案之一,只是为了帮助您开始一些链接.

This is an incredibly broad topic and lots of it depends on how you implement the various parts of your app. Below is one of the many possible answers, just in an effort to get you started with some links.

如果您的应用程序将其数据存储在Firebase数据库产品之一中(实时数据库,或 Cloud Firestore ),或者是否将文件存储在

If your app stores its data in one of Firebase database offerings (Realtime Database, or Cloud Firestore), or if it stores files in Cloud Storage through Firebase, then you'll likely want to store the role of each user as a custom claim in the profile of that user.

Firebase身份验证文档显示了如何设置此类自定义声明,例如如何从Node.js脚本中将用户的admin属性设置为true:

The Firebase Authentication documentation shows how to set such custom claims, for example how to set the admin property of a user to true from a Node.js script:

admin.auth().getUserByEmail('user@admin.example.com').then((user) => {
  // Confirm user is verified.
  if (user.emailVerified) {
    // Add custom claims for additional privileges.
    // This will be picked up by the user on token refresh or next sign in on new device.
    return admin.auth().setCustomUserClaims(user.uid, {
      admin: true
    });
  }
}).catch((error) => {
  console.log(error);
});

类似地,您可以在role属性中设置用户角色.然后,您可以签入实时数据库 Cloud Firestore

Similarly you could set your user roles in a role property. Then you can check in the server-side security rules of the Realtime Database, Cloud Firestore, or Cloud Storage if the user has a role that allows them access to the specific data they're trying to access.

然后,您可以在客户端代码中将用户令牌解码为可以访问相同的声明并为它们优化用户界面

In the client-side code you can then decode the user's token to get access to the same claims and optimize the UI for them

这篇关于如何在Firebase中创建不同的用户组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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