Skip to content

kltk/prisma-extension-rls

Repository files navigation

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];

About

Support Row Level Security with Prisma

Resources

Stars

Watchers

Forks

Packages

No packages published