A practical walkthrough of using Supabase with Next.js: auth, Postgres, row-level security (RLS), and safe environment setup.
…and a set of tools around it.
This guide focuses on the parts that matter most when you’re building a production Next.js app.
Keep your environment variables organized:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEY (server-only)Never expose the service role key to the client.
Rules of thumb:
NEXT_PUBLIC_ are accessible in the browserEven if you start simple, you’ll appreciate Postgres later:
If you’re using Prisma, treat Supabase as “just Postgres”.
Supabase adds convenience, but your data model should remain portable and well-structured.
RLS is the #1 reason Supabase apps stay secure.
Basic idea:
Example policy:
sql-- Only allow users to read their own rows CREATE POLICY "Users can read own profile" ON profiles FOR SELECT USING (auth.uid() = user_id);
If you disable RLS “just to make it work”, you’re creating a future security incident.
Client-side:
Server-side:
If you’re also using NextAuth, be careful not to create two competing auth systems. Pick one as the primary source of identity.
When uploading to Supabase Storage:
blogs/<slug>/<filename>Use Storage for binary assets (images, files), not for Markdown or structured content.
LIMIT / OFFSET or cursor patternsselect * in hot pathsRemember: Postgres performance issues are usually schema or query issues, not Supabase issues.
Add this checklist to your README to avoid common production mistakes:
USING (true) policies in productionauth.uid() correctlyNEXT_PUBLIC_* vars reviewed and intentional.env.local excluded from version controlSupabase is a great “batteries included” platform, but the real power is:
you’re still using Postgres
If your app is secure, fast, and maintainable, it’s because your data model and policies are solid; not because of magic abstractions.
Share your reaction:
Loading comments...
Continue exploring similar topics
A practical blueprint for designing PostgreSQL schemas that scale: from modeling and constraints to indexing, migrations, and performance debugging.
Hard-won lessons from shipping Next.js App Router apps: data fetching patterns, caching, server actions, and common footguns.
Learn essential database design principles, normalization techniques, indexing strategies, and how to build scalable data architectures for modern applications.