Next.js Discord

Discord Forum

Multi-tenancy

Unanswered
NicolasQuintero posted this in #help-forum
Open in Discord
Hello!

Does anyone have any idea how to set up a multi-tenancy architecture with Supabase?

I've seen that with RLS, you can create a companies table, and for the tables you create, add a company column and set up policies so that each user only has access to their own information.

I also found this: https://usebasejump.com

7 Replies

@NicolasQuintero Hello! Does anyone have any idea how to set up a multi-tenancy architecture with Supabase? I've seen that with RLS, you can create a `companies` table, and for the tables you create, add a `company` column and set up policies so that each user only has access to their own information. I also found this: https://usebasejump.com
when using supabase, you can create RLS as you said. Like that you have one single data structure and multiple tenants can create their own data sets inside this data structure. Though RLS the policies are created so that you can always be secure to share only the details that is the company allowed to see
Pygmy Nuthatch
@NicolasQuintero You can also make a roles table and a finction that will use auth.uid() and a table join to get the users role or company, to do this make a trigger on auth.users and copy info of ur choosing and the default company (or null) to public.users (dm me if nescessary) https://supabase.com/docs/guides/auth/managing-user-data
Pygmy Nuthatch
Chilax
@Pygmy Nuthatch I fell like the solution in code could be very lengthty
very lengthly threads are allowed. Also for that we have a specific thread for this stopic
@NicolasQuintero solved?