简体   繁体   English

如何在Firebase Web中创建两个用户组

[英]How To Create Two User Groups in Firebase Web

I am developing a web app which uses Firebase Authentication and Real-time Database. 我正在开发一个使用Firebase身份验证和实时数据库的Web应用程序。 The sign-in method is via Google and then if the user is new he/she will be ask if whether he/she is a teacher or student. 登录方法是通过Google进行的,然后,如果用户是新用户,他/她将被问及他/她是老师还是学生。

Teacher: can create classrooms and add students using their user.uid. 老师:可以创建教室并使用他们的user.uid添加学生。 Each classroom has a unique classroom id. 每个教室都有唯一的教室ID。 Can view the list of their students. 可以查看他们的学生列表。

Student: can view their classroom, and classmates. 学生:可以查看他们的教室和同学。

So How do I code two different types of users in Firebase for my web app? 那么, 如何在Firebase中为我的Web应用编写两种不同类型的用户代码? What will be the rules to use in the database? 在数据库中使用什么规则?

[UPDATED] [更新]

You could try this the simple way: 您可以尝试以下简单方法:

  1. Create a JSON object to store the users information in a field depends on the usage: 创建JSON对象以将用户信息存储在字段中取决于用法:

    • a field isTeacher of type boolean (assume you won't add other user type) or boolean类型的字段isTeacher (假设您不会添加其他用户类型)或
    • a field userType of object contain all the feature types (isTeacher: boolean , isStudent: boolean , isHeadmaster:boolean , etc.) or 对象的字段userType包含所有要素类型(isTeacher: boolean ,isStudent: booleanisHeadmaster:boolean等)或
    • a field of userType of type string 字符串类型的userType字段
  2. Create a method or condition to check the field of the user document whether is true for a particular user type / compare string (depends which one you use) by using if or switch case 通过使用ifswitch case,创建一种方法或条件来检查用户文档的字段对于特定用户类型/ compare string是否true (取决于您使用哪个compare string

  3. Under each case / condition, show the elements of the web according to their privilege. 在每种情况下,请根据其权限显示网络元素。

  4. After signed-in, before the page load, do the checking using the function created 登录后,在页面加载之前,请使用创建的功能进行检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建 Firebase web user.reauthenticateWithCredential() 方法所需的“凭据”对象? - How to create “credential” object needed by Firebase web user.reauthenticateWithCredential() method? 如何创建Firebase web user.reauthenticate()方法所需的“凭证”对象? - How to create “credential” object needed by Firebase web user.reauthenticate() method? FIREBASE phoneAuth (LinkWithPhoneNumber)。 稍后如何在 Firebase Web 中更改用户的关联电话号码。 ( nodejs, Create-react-app )? - FIREBASE phoneAuth ( LinkWithPhoneNumber ) . How to change a user's linked phone number later in Firebase Web. ( nodejs, Create-react-app )? 如何对Firebase Web App进行子查询以创建表 - How to subquery Firebase Web App to Create a table 如何使用JavaScript在Firebase中创建新用户 - How to create a new user in firebase using javascript 如何在firebase中创建两个onCreate function - How to create two onCreate function in firebase 如何仅在 Firebase 3 中创建用户而不对其进行身份验证? - How to just create an user in Firebase 3 and do not authenticate it? 如何在Firebase Firestore中创建与用户相关的数据 - How to create data related to user in Firebase Firestore Firebase“手动”创建用户 - Firebase create user “manually” firebase 创建用户 promise - firebase create user promise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM