Hi Bubblers! I started to build a multitenant SaaS and I’m trying to figure out the best way to structure my database and privacy rules:
Requirements:
- One user can create multiple companies.
- The user can invite people to each one the the companies
- An user can belong to one or multiple companies
- All the data will be filtered (securely) by the current company the user started a session on, this means every data collection will have a relation column “company”
- The same user can have a different role in every company he belongs to (Admin in Company A, Editor in Company B)
The way I’m trying to manage this is having a table for the relation company<>User<>Role
My question is how can I load the current company and role to the user session so the user can only see information from that company only and with the proper role permissions securely?
Any help or example is appreciated.