Search code examples
reactjsfirebasefirebase-realtime-databaseuser-roles

How to store data based on role levels using firebase and react


I am currently working on my final year project using react and firebase,

I have been working with firebase and been able to store the data directly,

but now I want to give role-based access to the users.

This is the* hierarchy * of users to store all data which is received and topmost level user i.e principal can read and write all the data ( principal, vice principal, hod, faculties) branches, *lower level user i.e vice-principal should not be able to read and write the data(fields in particular) associated with principal but can read and write the data associated with(vice principal, hod, faculties)* branches. and so on.....

to be more clear

I would appreciate any help. Thanks in advance.


Solution

  • When you create a user in the system copy their uid into a user collection and assign the user a role when they are created. Then in the future query that user by their uid to see what role they have and give them access to the content/functionality in question, based on the query response.