Supabase Is Retiring anon and service_role Keys: Switch to Publishable and Secret Keys
If your app was built a while ago, or your AI tool followed an older tutorial, it probably talks to Supabase with a long key that starts with eyJ. That’s a legacy key, and Supabase says it’s on the way out:
Supabase is deprecating the
anonandservice_rolekeys by the end of 2026. (Supabase: Migrating to publishable and secret API keys)
The good news: you can move over one piece at a time, because both kinds of keys work side by side until you turn the old ones off. Nothing breaks just because you created the new keys.
Which key replaces which
| Legacy key | Replace it with | Where it belongs |
|---|---|---|
anon (long eyJ… JWT) | Publishable key sb_publishable_… | Browser code, mobile apps, anything public |
service_role (long eyJ… JWT) | Secret key sb_secret_… | Servers, Edge Functions, workers only |
The publishable key has the same low privileges as anon, so your Row Level Security policies behave exactly the same. The secret key, like service_role, bypasses Row Level Security, so it must never reach the browser. One nice upgrade: Supabase says secret keys return a 401 if someone uses them from a browser. (Supabase: Migrating to new API keys)
Not sure which keys your app uses today? Search your project for eyJ, anon, and service_role. Our environment variables guide explains which values are public and which are secret.
Step 1: Create the new keys
In the Supabase Dashboard, open Settings → API Keys and pick the Publishable and secret API keys tab. If you see a Create new API keys button, your project only has legacy keys so far. Creating new ones is safe: they’re added next to the old ones, which keep working.
Step 2: Swap the publishable key in your frontend
Anywhere the browser uses the anon key, use the publishable key instead. In most Lovable, Bolt and Cursor apps that’s one environment variable:
VITE_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...
Two traps here:
- Use the name your code actually reads. If your code reads
VITE_SUPABASE_ANON_KEY, either put the new key under that name or update the code. Adding a differently named variable does nothing. - Redeploy after changing it. Vite bakes
VITE_values into your app when it builds, so the live site keeps the old key until the next build. Our blank page guide covers this in detail.
Step 3: Swap the secret key on your server
Anywhere a server you control uses service_role, switch to the secret key, kept in a server-side environment variable or secret, never one with a VITE_ or NEXT_PUBLIC_ prefix.
Step 4: Update Edge Functions (the step people miss)
Supabase adds two new environment variables to Edge Functions, SUPABASE_PUBLISHABLE_KEYS and SUPABASE_SECRET_KEYS. Unlike the old ones, they hold JSON, not a plain string, so you read the key by name. The keys you created in step 1 are named default:
// before
const secretKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
// after
const secretKey = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']
The other surprise: the new keys aren’t JWTs. Send them on the apikey header only. If they also go on Authorization: Bearer, which many clients do by default, the platform can reject the call with Invalid JWT. Supabase’s guide says the built-in verify_jwt check only understands the legacy keys, so for functions called with the new keys you set verify_jwt = false and check who’s calling in your own code (or use their @supabase/server SDK, which does it for you). (Supabase: Migrating to new API keys)
Don’t just flip verify_jwt off and walk away. A function with no check in its code is open to anyone with the URL.
Step 5: Find the hidden callers
There’s no automatic “who still uses the old key” report, so check by hand:
- Database Webhooks and
pg_netcalls. These usually send theservice_rolekey asAuthorization: Bearer. Change them to send the secret key on anapikeyheader, and keep that key in Vault rather than pasting it into SQL. - Cron jobs, workers, and scripts.
- Your CI or deploy pipeline.
- Third-party tools you pasted a key into.
- Mobile app versions people already installed.
Step 6: Turn off the legacy keys
When nothing uses them anymore, deactivate the legacy keys in Settings → API Keys. Supabase says this is reversible, so if something breaks you can turn them back on, fix the straggler, and try again.
A prompt for your AI tool
This project uses Supabase. Find every place that uses a Supabase API key:
frontend env vars, server code, Edge Functions (supabase/functions/),
SQL migrations with pg_net or database webhooks, and scripts.
For each one, tell me whether it uses the legacy anon key, the legacy
service_role key, or the new sb_publishable_ / sb_secret_ keys, and what
needs to change to use the new keys. Edge Functions should read
SUPABASE_SECRET_KEYS (JSON, key "default") and send keys on the apikey
header, not Authorization: Bearer. Report first; don't change files yet,
and never print key values.
The short version
- Create the new keys in Settings → API Keys. The old ones keep working.
- Publishable key in the frontend, then redeploy.
- Secret key on the server, never in the browser.
- Edge Functions: read
SUPABASE_SECRET_KEYSas JSON, use theapikeyheader, and authorize in code. - Check webhooks,
pg_net, cron jobs and scripts. - Deactivate the legacy keys (reversible).
While you’re in there, run the pre-launch security checklist to make sure no secret key ever made it into your live JavaScript.
Official sources used: Supabase: Migrating to publishable and secret API keys · Supabase: API keys. Checked November 2026.
Ready to ship without guessing the next fix?
The Ship It Kit puts the prompts, deploy steps and pre-launch checklist in one place for Lovable, Bolt, Cursor and Replit apps. One-time $19. Launch price: $19 $17 until November 14, 2026.