Supabase "Legacy API keys are disabled": switch to publishable and secret keys
Your app, an Edge Function or a script suddenly fails with Legacy API keys are disabled, or Supabase keeps reminding you to move off your anon and service_role keys. Supabase is retiring those keys by the end of 2026. Here's how to switch to the new publishable and secret keys without breaking anything.
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €49What's happening
Supabase has two kinds of API key. The old ones are the anon and service_role keys, long strings starting with eyJ. The new ones are the publishable key (sb_publishable_...) and secret keys (sb_secret_...). Supabase's API keys docs say it "is deprecating the anon and service_role keys by the end of 2026."
anonbecomes the publishable key. It's safe in the browser and your RLS policies work the same.service_rolebecomes a secret key. It's server only, because it skips RLS.
You see Legacy API keys are disabled when something sends an old eyJ... key to a project where the legacy keys have been switched off. If you restored a paused project or someone in your team switched the old keys off, this is usually why.
1. Find out which part of your app is failing
Open your live site, open the browser's developer tools, go to the Network tab and retry the action that fails. A failed request to https://your-project.supabase.co means your frontend still uses the old key. If the frontend is fine, check your Edge Function logs, then any server, cron job or webhook that calls Supabase.
2. Create the new keys
In the Supabase dashboard go to Settings, then API Keys, and open the Publishable and secret API keys tab. If you only see a Create new API keys button, click it. Supabase's migration guide says this is safe: it adds the new keys next to the old ones, and the old ones keep working.
3. Swap the key in your frontend
Replace the anon key with the publishable key wherever your app creates its Supabase client:
const supabase = createClient(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY // was the anon key (eyJ...)
)
If the key lives in an environment variable on Vercel, Netlify or Lovable, change it there and redeploy. VITE_ and NEXT_PUBLIC_ values are baked in when the app is built, so changing the variable alone does nothing. Our guide to env variables in production covers this. Mobile apps already on people's phones keep the key they were built with until users update.
4. Swap the key in server code and Edge Functions
Replace service_role with a secret key everywhere on the server. Never put an sb_secret_ key in browser code. Supabase rejects secret keys sent from a browser with a 401, and a leaked one gives full access to your data.
Edge Functions get two new environment variables, SUPABASE_PUBLISHABLE_KEYS and SUPABASE_SECRET_KEYS. They hold JSON, not a plain string, and the first key is named default:
// before
const secretKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
// after
const secretKey = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']
5. Send the new keys in the right header
The new keys aren't JWTs. Send them in the apikey header, not as Authorization: Bearer. Sending them as a Bearer token is the usual cause of Invalid JWT after switching. Two places this bites:
- Edge Functions that rely on the built-in
verify_jwtcheck. Supabase's guide says to setverify_jwt = falsefor those functions and check the key or the user's session in your own code (or use the@supabase/serverSDK). - Database Webhooks and
pg_netcalls that send theservice_rolekey as a Bearer token. Edit each webhook: remove thatAuthorizationheader and add anapikeyheader with a secret key. Store the key in Vault rather than pasting it into SQL.
6. Check nothing still uses the old keys, then turn them off
Supabase has no usage meter for the old keys, so check by hand: your frontend, every Edge Function, servers, cron jobs, CI scripts, webhooks, third-party tools and old mobile app versions. Then turn the legacy keys off under Settings, API Keys. Turning them off can be undone if you find something you missed.
One exception: if you're turning the old keys off because one leaked, don't turn them back on to unblock a forgotten script. That puts the leaked key back in service. Fix the script instead. If a key ended up in your frontend code, our guide to an API key exposed in your app walks through the clean-up.
Quick checklist
- New publishable and secret keys created
- Frontend uses
sb_publishable_and has been redeployed - Servers and Edge Functions use
sb_secret_, never in the browser - New keys sent in the
apikeyheader - Webhooks and
pg_netcalls updated - Nothing left using
eyJ...keys, then legacy keys turned off
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €49Still stuck?
Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Get the €49 fix, or start with a free scan.
Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.