prisma-extension-supabase-rls icon indicating copy to clipboard operation
prisma-extension-supabase-rls copied to clipboard

What is RLS_DATABASE_URL

Open AndreiOvercode opened this issue 1 year ago • 8 comments

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

AndreiOvercode avatar Sep 11 '23 12:09 AndreiOvercode

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.

Jonatthu avatar Sep 30 '23 15:09 Jonatthu

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.

louishugens avatar Oct 02 '23 10:10 louishugens

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

Jonatthu avatar Oct 02 '23 13:10 Jonatthu

thanks a lot @Jonatthu

louishugens avatar Oct 02 '23 14:10 louishugens

@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.

louishugens avatar Oct 02 '23 15:10 louishugens

Can you screenshot?

Jonatthu avatar Oct 02 '23 15:10 Jonatthu

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: image

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.

louishugens avatar Oct 02 '23 15:10 louishugens

I also get that TS error

nbaasmf avatar Oct 26 '23 10:10 nbaasmf

for anyone seeing above, you can just take out the explicit type annotation for client.

so ...((client: PrismaClient) => { just becomes

...((client) => {

theonlydaleking avatar Oct 16 '24 22:10 theonlydaleking

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?

remusris avatar Oct 16 '24 23:10 remusris