0
Challenge · 04Setup, the Mental Model & Your First Secure App
Keys & clients: publishable vs secret
Securityused in ~100% of apps
Every Supabase project hands you two keys on the exact same settings page. One is meant to be pasted into public client code, committed to a public repo, and read out of your browser's network tab by anyone who opens DevTools. The other, used the same way, hands a stranger your entire database with every Row Level Security policy switched off. They are two short strings that look almost identical — and the only thing separating "safe to expose" from "total breach" is which one goes into which file. Getting it backwards raises no error. It just works, for everyone, until someone notices.
Core idea. A Supabase project ships a publishable key (safe anywhere — it only names the project and selects the low-privilege anon/authenticated Postgres role, so RLS still governs every row) and a secret key (authenticates as service_role, which carries BYPASSRLS and skips policies entirely). The browser client is always built on the publishable key — and, this is the trap, so is the server-side client that reads and writes on behalf of a signed-in user. The secret key is reserved for a separate, rare, server-only admin client that deliberately needs to see past RLS.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
.envgit-ignored
Tap a line to toggle its VITE_ prefix. P = public, S = server-only.
app.4f2.jsSHIPPED TO BROWSER · PUBLIC
import.meta.env.VITE_API_BASE_URL // → "https://api.pulse.app"
server (process.env)NEVER SENT TO BROWSER
ANALYTICS_ID // stays here, value hidden from users
DATABASE_URL // stays here, value hidden from users
STRIPE_SECRET_KEY // stays here, value hidden from users
Safe build. Only the public URL/id were prefixed and inlined; the real secrets stayed on the server. The rule: a prefix makes a value public forever, so only ever prefix things you would print on a billboard.
↑ play a little first, then dig in