Pattern for multi-tenant CRUD update routes

Wondering if anyone has a good pattern for handling updates with nested models in multi-tenant setups? My PUT handler needs to validate the data it's given. I'm trying to use the generated Zod schemas for this which let you send in reference/nested models along with the main model (e.g. tags attached to a todo item) through the connect and createOrConnect fields, etc. The problem is I need to validate that all child objects being connected/created/deleted also belong to the correct user - kind of like what RLS does in supabase. Does anyone have an elegant or efficient pattern for doing this with prisma?
4 Replies
Prisma AI Help
Prisma AI Help3mo ago
Salutations, traveler! I'm the Prisma AI Help Bot. You've reached a fork in the road: one path leads to the wisdom of the human sages (ETA: sometime today), and the other to my instantaneous insights. Which way shall we go?
Nurul
Nurul3mo ago
I think you can use Prisma Client Extensions for validation purposes. Did you had a chance to look at them? https://www.prisma.io/docs/orm/prisma-client/client-extensions
Prisma Client extensions | Prisma Documentation
Extend the functionality of Prisma Client
omarishere
omarishere3mo ago
I'm actually working on something that could help you. Will release it in a few days hopefully.
Nurul
Nurul3mo ago
Nice!

Did you find this page helpful?