IssueRaiser

Support for row-level security (RLS)

## Problem <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] --> Currently, if we want to guarantee that user's requests have enough permissions to run a query, we have to keep coding `where:{...} ` clauses everywhere in our code. Depending on the size of the code base, it can be extremely hard to make sure that all query conditions are correct, updated and concise with the data model. ```ts // check if the venue is the actual owner of the ticket if (id) { const ticket = await prisma.ticket.findFirst({ where: { id, venueId: context.venue.id, }, }) if (!ticket) { throw new Error('Ticket not found') } } // there's no way to verify to make sure the upsert has enough permission to update or create await prisma.ticket.upsert({ where: { id, }, update: data, create: { ...data, venueId: context.venue.id, }, }) ``` ## Suggested solution We could have a way to implement some sort of `@@security` directly on the `schema.prisma` file. This way, we can check the user's permissions directly on the database, saving some back-and-forth queries and also making sure that rules will always be respected anywhere in the codebase. An API that follows the same `where` principles applied to the models will allow a more flexible and powerful way to implement a granular security. ```prisma @@security( name: 'Blah', // Name of the rule (impo

Posted by wladpaiva on Apr 8, 2022, 1:08 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,500 issues0 comments

ux (Other)

Support for row-level security (RLS)

wladpaivaApr 8, 2022, 1:08 PM

## Problem <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] --> Currently, if we want to guarantee that user's requests have enough permissions to run a query, we have to keep coding `where:{...} ` clauses everywhere in our code. Depending on the size of the code base, it can be extremely hard to make sure that all query conditions are correct, updated and concise with the data model. ```ts // check if the venue is the actual owner of the ticket if (id) { const ticket = await prisma.ticket.findFirst({ where: { id, venueId: context.venue.id, }, }) if (!ticket) { throw new Error('Ticket not found') } } // there's no way to verify to make sure the upsert has enough permission to update or create await prisma.ticket.upsert({ where: { id, }, update: data, create: { ...data, venueId: context.venue.id, }, }) ``` ## Suggested solution We could have a way to implement some sort of `@@security` directly on the `schema.prisma` file. This way, we can check the user's permissions directly on the database, saving some back-and-forth queries and also making sure that rules will always be respected anywhere in the codebase. An API that follows the same `where` principles applied to the models will allow a more flexible and powerful way to implement a granular security. ```prisma @@security( name: 'Blah', // Name of the rule (impo

Comments (0)

No comments yet. Start the discussion.

Comment on this issue