← Back to blog

Oct 26, 2026 · 10 min read

Building SaaS on Supabase: What We've Learned About Auth, RLS, and Postgres

Supabase gives you a Postgres database, authentication, and a generated API in one package. After building several SaaS products on it, here's what works, what doesn't, and what to watch out for.

SupabasePostgreSQLSaaS

Supabase's pitch is appealing: a Postgres database, authentication, file storage, and a generated REST API, all in one platform. For SaaS development, it removes a lot of the boilerplate you'd normally build yourself.

We've built several SaaS products on Supabase over the past two years. Here's what we've learned, organized around the three areas where most of the complexity lives: auth, Row Level Security, and database design.

Authentication: simpler than building your own, with caveats

Supabase Auth handles the hard parts of authentication: password hashing, session management, email verification, OAuth flows, and JWT issuance. You get password, magic link, OTP, social login, and SSO out of the box.

The mental model is that auth issues a signed JWT that carries the caller's identity, and your database can read that JWT to make per-user decisions. This is cleaner than building auth yourself, and it integrates with RLS in a way that external auth providers don't.

What works well:

  • Email and password signup takes an afternoon, not a week.
  • Social login (Google, GitHub, etc.) is configuration, not implementation.
  • The JWT carries the user ID, which RLS policies can use directly.
  • Server-side auth for Next.js works with cookies and SSR.

What to watch out for:

  • JWT refresh handling in SSR is tricky. In a client-side app, Supabase handles token refresh automatically. In a server-rendered app (Next.js, SvelteKit), you need to manage the cookie-based session carefully. The @supabase/ssr package helps, but it's a different mental model than client-only auth.
  • Rate limiting and bot detection are not on by default. Turn them on. Auth endpoints without rate limiting are a brute-force target.
  • The service role key bypasses RLS. This is by design (it's for server-side operations that need full access), but it means any code path that uses the service role key is a security-critical path. Don't expose it to the client, ever.

Row Level Security: the thing that makes Supabase work

RLS is the core of Supabase's security model. Instead of writing authorization logic in your application code, you write it as Postgres policies that run inside the database. Every query is filtered by the policies that apply to the current user.

This is powerful, but it's also the area where most teams get into trouble.

The default grants problem. When you create a new table in the public schema, Supabase grants every privilege to the anon, authenticated, and service_role roles automatically. Adding RLS policies doesn't revoke those grants. A table protected only by policies still gives anon an insert path if you never explicitly revoke the grant.

This is the single most common security mistake we see. Teams enable RLS, write policies, and assume the table is secure. But the grants are still there, and a missing or incorrect policy can open a path that the team didn't intend.

The fix is to explicitly set grants for each role on each table:

-- Revoke everything by default
REVOKE ALL ON public.user_data FROM anon, authenticated;

-- Grant only what the app needs
GRANT SELECT ON public.user_data TO authenticated;

Policy design. A good RLS policy is short and specific. The most common pattern is "users can only see their own data":

CREATE POLICY "users see own rows"
ON public.user_data
FOR SELECT
TO authenticated
USING (user_id = auth.uid());

The auth.uid() function returns the current user's ID from the JWT. This is what connects auth to RLS.

What goes wrong:

  • Policies that are too permissive. A policy like USING (true) on a table with sensitive data is a bug, even if you "intended" it for testing.
  • Forgetting that the service role bypasses RLS. If your admin panel uses the service role key, RLS doesn't apply. That's fine for admin operations, but it means your admin code needs its own authorization checks.
  • Not testing policies. RLS policies are code. They need tests. Supabase supports writing tests in SQL under supabase/tests/, and you should.

Database design: your schema is your API

Supabase generates a REST API from your schema automatically. The shape of your data is the shape of what clients can do. This is a different mental model from building a custom API, and it has implications.

Design tables for the API you want. If you want clients to be able to fetch a blog post with its author in one request, you need a view or a foreign key relationship that makes that possible. The generated API follows your schema, not your intentions.

Use Postgres features. Supabase gives you a full Postgres database. Use it. Triggers for updated timestamps, foreign keys for data integrity, views for complex queries, and functions for business logic that's better expressed in SQL than in application code.

Don't rebuild what PostgREST already does. If you're writing a REST server that forwards CRUD operations to the database, you're rebuilding what Supabase generates for you. Put that effort into the schema instead.

What we'd do differently

If we were starting a new SaaS project on Supabase today, here's what we'd do from day one:

  1. Enable RLS on every table before writing any application code. Make it the default, not an afterthought.
  2. Write explicit grants for every table. Don't rely on the defaults. Revoke everything, then grant what's needed.
  3. Write RLS policy tests. They're cheap to write and catch the most dangerous bugs.
  4. Use the service role key only in server-side code that needs it. For everything else, use the anon or authenticated client with RLS.
  5. Start with email/password auth and add social login later. Don't over-engineer auth on day one.
  6. Use database views for complex API responses. They're more efficient than fetching related data in multiple round trips.

The honest assessment

Supabase is a good choice for SaaS products that need a database, authentication, and an API without building all three from scratch. It's not a replacement for a backend when you need complex business logic, but it removes enough boilerplate that you can focus on the parts that matter.

The main risk is treating it as "Postgres but easier" and skipping the security fundamentals. RLS, grants, and policy testing are not optional. They're the core of what makes Supabase safe to use in production. Get those right, and the rest is straightforward. Get them wrong, and you have a data breach waiting to happen.

Need help applying this?

Schedule call →