prisma-extension-rls
v1.1.0
Published
Support Row Level Security with Prisma
Downloads
10
Readme
prisma-extension-rls
The Prisma RLS extension enhances Prisma app security by using PostgreSQL's RLS to enforce fine-grained access controls at the database level.
Installation
npm install prisma-extension-rls
Usage
Row Level Security Reference
code example
// 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];