Reputation:
I am developing a web app which uses Firebase Authentication and Real-time Database. 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.
Teacher: can create classrooms and add students using their user.uid. Each classroom has a unique classroom 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? What will be the rules to use in the database?
Upvotes: 1
Views: 329
Reputation: 3748
[UPDATED]
You could try this the simple way:
Create a JSON object to store the users information in a field depends on the usage:
isTeacher
of type boolean (assume you won't add other user type) or userType
of object contain all the feature types (isTeacher: boolean, isStudent: boolean, isHeadmaster:boolean, etc.) oruserType
of type stringCreate 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
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
Upvotes: 2