The Prisma RLS extension enhances Prisma app security by using PostgreSQL's RLS to enforce fine-grained access controls at the database level.
npm install prisma-extension-rls
// for supabase
import { PrismaClient } from '@prisma/client';
import { supabaseExtension } from 'prisma-extension-rls';
// create client
const prisma = new PrismaClient()
// extend supabase extension
.$extends(supabaseExtension);
// get & verify claims
const claims = {
aud: 'authenticated',
role: 'authenticated',
sub: '1',
// ...
};
// set claims
const claimedClient = prisma.$supabase(claims);
const model = claimedClient[modelName];
// for custom
import { PrismaClient } from '@prisma/client';
import { rlsExtension } from 'prisma-extension-rls';
// create client
const prisma = new PrismaClient()
// extend rls extension
.$extends(rlsExtension);
// get rls data
const data = {
appid: 'appid',
json: {},
};
// set rls data
const rlsClient = prisma.$rls(data);
const model = rlsClient[modelName];