RLS Connection Error with Next.js + Prisma (service_role)

After enabling RLS on my tables, my Next.js backend API routes using Prisma Client are failing with PrismaClientInitializationError: Can't reach database server. This error occurs even when the Prisma Client is configured to use the service_role key and the direct database connection string (port 5432). The most confusing part is that a CLI command like npx prisma migrate dev connects successfully, but the exact same Prisma Client fails within the Next.js application runtime. My understanding is that the service_role key should bypass RLS entirely. Could you please help me understand why enabling RLS would cause a connection-level failure for a privileged client, and why the CLI and the app runtime behave differently?
1 Reply
silentworks
silentworks3w ago
Prisma doesn't use any keys (anon nor service role). It uses the direct connection with the database password you set when you first create your project on Supabase. The keys are only for the Supabase SDKs, so @supabase/supabase-js in the case of it's Javascript SDK. These are never used with Prisma. You can see the Prisma setup quickstart here https://supabase.com/docs/guides/database/prisma.

Did you find this page helpful?