-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One Prisma client per call? #1
Comments
Hi @WesleyYue thanks for your question.
I think I would still have one client per application, or maybe two (not including what Prisma would use to run its migrations using the 1 - A client that was used by the application to execute queries based on behalf of a user. This would be the client that 2 - I may still have some admin client that bypasses RLS for its role (this would not use
I don't think that would be the case that "each Prisma client now has their own unique extension with the appropriate claims" because there is a What I mean is, seen in this example: const prisma = new PrismaClient({
datasources: { db: { url: process.env.RLS_DATABASE_URL } },
}).$extends(
useSupabaseRowLevelSecurity({
/**
* Return the decoded current user from the context
*/
claimsFn: () => context.currentUser,
/**
* Throw a RedwoodJS ForbiddenError if the policy is violated
*/
policyError: new ForbiddenError('Violates RLS.'),
})
) The So, this "app res-enforced client" can be used over an over for any user. Perhaps I am not understanding your question, but beyond an app or admin Prisma client, what other clients do you envision needed in your application? For Supabase, it is common to use their CREATE POLICY "Authenticated users can modify Pedals" ON "public"."Pedal"
AS PERMISSIVE FOR UPDATE
TO rls_user
USING (auth.jwt() ->> 'role' = 'authenticated')
WITH CHECK (auth.jwt() ->> 'role' = 'authenticated'); But, I guess if your policy uses "some other" check then the default claimsSetting of this client extension would not work. It's geared to sending JWT claims so that I imagine you could override the default Hope that helps! |
Thanks, I think was misunderstanding how Prisma extensions worked, and I was not aware that you can extend the same base client instance without concerns for conflicts as the returned client instances from .$extends() are isolated from one another. |
Hi, thanks for writing up this example. Do you have any guidance on how to manage the number of Prisma clients? Typically, you'd have one Prisma client for the application. Given that each Prisma client now has their own unique extension with the appropriate claims, what is the recommended pattern for managing Prisma client instances?
The text was updated successfully, but these errors were encountered: