user10312658
user10312658

Reputation:

How To Create Two User Groups in Firebase Web

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

Answers (1)

Angus
Angus

Reputation: 3748

[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:

    • a field isTeacher of type boolean (assume you won't add other user type) or
    • a field userType of object contain all the feature types (isTeacher: boolean, isStudent: boolean, isHeadmaster:boolean, etc.) or
    • a field of userType of type string
  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

  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

Upvotes: 2

Related Questions