Hi I am creating a dashboard where a user can belong to multiple tenants and have a different role per tenant and need help to know if my idea is in the right direction.
Normally a directus user can only have one role. However I already have a table for users in an existing database.
My Idea:
If i establish a one tbl_user to many directus_users relationship. Could this allow my to have a user to belong to multiple tenants with their respective roles?
Hmm - it seems like you should be able to make this work with the existing roles and permissions system. Few
clarifying questions…
- What does your tenancy model look like?
- Can you share a bit about the functionality you want to scope by tenant and by role?
- Are you planning to use the system Directus roles? Or you already have roles defined in your existing DB? If so what do those look like?
Hi thanks for responsing.
-
Many user can belong to many tenants.
-
So the dashboard is a ticketing platform. The dashboard will also be the client that makes api calls to a directus api. There are many kinds of tenants eg. promoters and venues. There are cases where a user will be an admin for a promotor but just a viewer for venues in order to look at statistics. So that requires the user to have different roles.
-
The plan is to use directus to build an api at the same time use directus roles to handle the authorization. There are existing roles however unused and are couple d too closely tenant type eg. bunch of if statements that check tenant type.
Think i solved it
I used a join table tbl_tenantusers that already exists and then create a M2O connection from directus_users to tbl_tenantusers.tenantusers_id. This will allow my exsting users to have more than one directus_user hence multiple roles. These users don’t have to use the directus dashboard so the directus_user doesn’t need email or password as it’s just used for permissions.
Glad you worked out a solution. If you’ve tested this and it works – roll with it.
I thought this was a great question and many others might have similar ones - so here’s a video that covers the way I’d tackle this one.