i followed the YT video to construct a SAAS platform, with each record is tie to a unique tenant.
But my challenge is, it’s annoyed if user need to manually select tenant, even most of the time they belongs to one tenant (a user can be in multiple tenant if needed)
is there are trick (without extension or customized script), i could use standard feature to pre-populate their tenant which tie to user if the user only have one tenant? e.g. user.tenants[0].id
update 10 May 2025:
a pic speak thousand words. i tried 3 different combination, string field is working but not relationship field
Hey, I think I have a similar multi tenancy situation going on. The user is always tied to one tenant but they can switch tenants on the fly. I am using the presets feature but not [0] as the "tenant" field is just an M2O. I use a presentation field (you can start from superheader extension from directus labs) to switch the tenant is assigned to at the specific time. Let me know if you need more info or if you think my use case is wildly different.
If a user is in multiple tenants, how would it know which one to use as the default?
I’d suggest you look at using a event hook Flow. You can use a ‘filter’ event and add the logic to automatically add in the current user’s tenant.
under Flow, there is no "on page load" event. And i don't prefer to use flow to identify tenant upon page save. reason being in the biz i am into, many time there is "space fields" that could be configure to show based on tenant level. meaning ideally when page load, before save, it trigger logics 1. Default my first tenant (99% a user only belongs to one tenant) 2. Show/Hide additional spare fields under collection based on client.
If you know you’ll have a lot of folks that are a part of different teams or tenants, you could add an additional relational field on the user level for current_tenant or active_tenant or whatever you prefer the naming convention to be. You’d set that once when the user is created or added to a tenant. And then give them the option to switch to a different tenant if they are part of more than one.
The only caveat there is we don’t have a prebuilt UI component or interface for the user to “switch tenants” so that’s something you’d have to build as a custom extension.
If you don’t want to create a custom extension, you could probably also just make it a flow they could run from any collection as well in you’re using the Data Studio as the “frontend” for your SaaS users.
Hey, I think I have a similar multi tenancy situation going on. The user is always tied to one tenant but they can switch tenants on the fly. I am using the presets feature but not [0] as the "tenant" field is just an M2O. I use a presentation field (you can start from superheader extension from directus labs) to switch the tenant is assigned to at the specific time. Let me know if you need more info or if you think my use case is wildly different.
– pepeday