prisma-extension-supabase-rls
prisma-extension-supabase-rls copied to clipboard
What is RLS_DATABASE_URL
What is RLS_DATABASE_URL
and how do I get it? If I use
RLS_DATABASE_URL="postgres://rls_user
and
const users = await prisma .$extends( useSupabaseRowLevelSecurity({ claimsFn: () => ({ sub: '8a3611fb-204b-4cf1-8111-17269f9c7dce', }), }), ) .users.findMany();
I get an error Not authorised
To connect to Postgres, you need to first createustom password and use that to a a role with a cuthenticate in your connection string. The claimsFn should be the decoded JWT obtained using Supabase Auth. For more guidance, please refer to the README.md file in this repository. Reading it a few times should make the process clear.
Hi @Jonatthu,
It is still not clear to me how to get this extension in my project. Do i need to clone the repo inside my project? Thank you in advance.
Just copy the extension itself not the entire repo, then you can use it on prisma. Make sure you pass the claims on every single request
thanks a lot @Jonatthu
@Jonatthu would you accept to give a consultation on implementing this? I stumble upon a bunch of typescript errors. I need to move forward. Please let me know.
Can you screenshot?
here is the ts error
Argument of type '(client: PrismaClient) => DynamicClientExtensionThis<Prisma.TypeMap<Args_2 & { result: {}; model: {}; query: {}; client: {}; }>, Prisma.TypeMapCb, { result: {}; model: {}; query: {}; client: {}; }>' is not assignable to parameter of type '{ name?: string | undefined; query?: DynamicQueryExtensionArgs<{ $queryRaw?: unknown; $executeRaw?: unknown; $queryRawUnsafe?: unknown; $executeRawUnsafe?: unknown; profile?: unknown; appointment?: unknown; users?: unknown; skill?: unknown; category?: unknown; subCategory?: unknown; subSubCategory?: unknown; availab...'. Type '(client: PrismaClient) => DynamicClientExtensionThis<Prisma.TypeMap<Args_2 & { result: {}; model: {}; query: {}; client: {}; }>, Prisma.TypeMapCb, { result: {}; model: {}; query: {}; client: {}; }>' is not assignable to type '(client: DynamicClientExtensionThis<TypeMap<Args_2 & DefaultArgs>, TypeMapCb, DefaultArgs>) => { ...; }'. Types of parameters 'client' and 'client' are incompatible. Type 'DynamicClientExtensionThis<TypeMap<Args_2 & DefaultArgs>, TypeMapCb, DefaultArgs>' is missing the following properties from type 'PrismaClient<PrismaClientOptions, never, DefaultArgs>': $on, $use
here the screenshot:
I also ha this when passing the extention to the prisma client:
React Hook "useSupabaseRowLevelSecurity" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.
I also get that TS error
for anyone seeing above, you can just take out the explicit type annotation for client.
so
...((client: PrismaClient) => {
just becomes
...((client) => {
for anyone seeing above, you can just take out the explicit type annotation for client.
so
...((client: PrismaClient) => {
just becomes
...((client) => {
Do you know why you have this type error and why it goes away when you remove the explicit PrismaClient?