How to Integrate Prisma and Supabase Safely

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair prisma and supabase to build type-safe backends on managed Postgres databases. Prisma handles schema changes and queries while Supabase runs the database and auth services. This setup lets developers write queries in code and push schema updates fast. Still, default settings often mix admin tasks with daily app traffic. You need clear role boundaries to keep production data safe. How prisma and supabase handle roles and data flow Prisma connects to the underlying Postgres database

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams pair prisma and supabase to build type-safe backends on managed Postgres databases. Prisma handles schema changes and queries while Supabase runs the database and auth services.

This setup lets developers write queries in code and push schema updates fast. Still, default settings often mix admin tasks with daily app traffic. You need clear role boundaries to keep production data safe.

How prisma and supabase handle roles and data flow

Prisma connects to the underlying Postgres database using a standard connection string. That string holds a database user, a password, a host, and a port. Every query from your app runs with the permissions of that database user.

Every new Supabase project includes a default postgres role with admin privileges. Supabase does not grant full superuser status because that allows destructive database actions. Instead, the default postgres role gets extra permissions for common admin work. The password you create at project setup belongs to this admin role.

Supabase also sets up built-in roles like anon, authenticated, service_role, and authenticator. Client apps use those roles when they talk to the Supabase data API. Prisma takes a different path and talks straight to the Postgres database engine. When Prisma uses the default admin role, it bypasses Row Level Security rules. Your backend code then holds full power over every table and row.

Common failure modes and how to scope database roles

Many teams copy the default admin password into every app and developer laptop. Supabase warns against sharing this password with outside services you do not fully trust. Instead, Supabase recommends creating a separate database user for each service. Shared admin credentials create a big risk across your team and apps.

End-to-End Encryption + Prisma Cloud Compliance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

If an app key leaks, an attacker gains full admin control over your database. Unlogged queries from local tools also look identical to real app traffic. You cannot tell which person ran a destructive command during an incident. Queries run in the Supabase Dashboard use the default admin role too. Dashboard queries at least add a source comment to help you spot them.

You can fix this by splitting migration roles from runtime app roles. Keep the admin role for schema migrations in your build pipeline only. Create a custom Postgres user with limited table permissions for your running app. Grant this runtime user only the read and write rights it needs. Never let the runtime app user drop tables or change schemas.

You should also protect sensitive columns like emails, phone numbers, and card numbers. Even a scoped app role can return raw national IDs if queried by engineers. Keep developer laptops off the shared production connection string at all times. Give each service and tool its own database user and narrow network path. Review your active roles often and remove any unused service accounts right away.

Run guardrails and masking on the Postgres connection

Role grants and firewall rules are needed setup. Setup alone cannot check single SQL statements or mask sensitive rows in a response. By design, hoop.dev is an open-source proxy that sits beside Postgres, RDS, or Aurora as a sidecar for your Postgres. Clients and agent tools keep their credentials and point their connection string at the listener.

On each query, hoop.dev guardrails refuse disallowed drops, deletes, or table reads before they run. Next, hoop.dev data masking rewrites sensitive fields in returned rows that match your rules. Furthermore, hoop.dev holds SOC 2 Type II and logs every statement and verdict per resource. Check out the project on GitHub.

Frequently asked questions

Does Prisma use Supabase Row Level Security by default?

No, Prisma usually connects with a direct database role that bypasses Row Level Security. You must create a custom role without bypass rights if you want database policies enforced.

Should I use the default postgres role for my Prisma app?

No, the default postgres role has admin rights and should not run daily app queries. Create a dedicated database user with restricted table permissions for your Prisma backend instead.

How should teams separate Prisma migrations from app queries?

Use an admin role in your automated build pipeline to run schema changes safely. Give your live app a separate role that can only read and write table data.

The query runs. The emails stay hidden.