[英]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: 您可以尝试以下简单方法:
Create a JSON object to store the users information in a field depends on the usage: 创建JSON对象以将用户信息存储在字段中取决于用法:
isTeacher
of type boolean (assume you won't add other user type) or boolean类型的字段isTeacher
(假设您不会添加其他用户类型)或 userType
of object contain all the feature types (isTeacher: boolean , isStudent: boolean , isHeadmaster:boolean , etc.) or 对象的字段userType
包含所有要素类型(isTeacher: boolean ,isStudent: boolean , isHeadmaster:boolean等)或 userType
of type string 字符串类型的userType
字段 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 通过使用if
或switch
case,创建一种方法或条件来检查用户文档的字段对于特定用户类型/ compare string
是否true
(取决于您使用哪个compare string
)
Under each case / condition, show the elements of the web according to their privilege. 在每种情况下,请根据其权限显示网络元素。
After signed-in, before the page load, do the checking using the function created 登录后,在页面加载之前,请使用创建的功能进行检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.