Secrets
Your Supabase app still runs on the legacy anon and service_role keys Supabase is removing
Cataloged November 7, 2026 · Supabase · Lovable · Bolt · v0 · Cursor · Replit
Symptom
Nothing looks wrong. Sign-in works, data loads, and the app deploys. The code and the env still hold a long key that begins with eyJ, the legacy anon key, and sometimes a second eyJ key, the legacy service_role key. Supabase's API keys guide and the migrating guide say Supabase is deprecating the anon and service_role keys by the end of 2026. Use the publishable key (sb_publishable_xxx) and the secret key (sb_secret_xxx) instead. The announcement in GitHub discussion #29260 puts the deletion at late 2026, TBC: the legacy API keys will be deleted and removed from the Docs / Dashboard, and the app breaks if it has not migrated by then. No exact day has been published. A project restored from a pause from 1 November 2025 comes back without those legacy keys. New projects no longer have anon and service_role available. The same docs say that if a tool, tutorial, or AI assistant tells you to copy a long key that begins with eyJ, it was written for the legacy keys.
Root cause
The anon key and the service_role key are the legacy API keys. Supabase is replacing them with a publishable key and a secret key, and those new keys are short strings, not JWTs. The anon key maps to the publishable key, which is what browsers, mobile and desktop apps, CLIs, and public source should send. The service_role key maps to the secret key, which is what servers, Edge Functions, workers, and other backend code should send. A publishable key has the same low privileges as the anon key. Row Level Security behaves the same way, and Supabase Auth is unchanged, so a signed-in user still gets their own JWT. A secret key bypasses RLS. If a browser sends a secret key, Supabase returns HTTP 401, matched on the User-Agent header. You can keep a separate secret key for each backend component, so one leak forces only that one key to be rotated. Secret keys are hidden by default, each reveal is recorded in the org Audit Log, and deleting a secret key revokes it instantly. Supabase's docs say that if a tool, tutorial, or AI assistant tells you to copy a long key that begins with eyJ, it was written for the legacy keys. Creating the new keys does not revoke the legacy keys, and both work at the same time, so an older project can switch one place at a time. An older project that still has only the legacy keys shows a Create new API keys button in Settings > API Keys, on the Publishable and secret API keys tab. The new keys are named default. The announcement in GitHub discussion #29260, by maintainer kangmingtay, gives the timetable: June 2025 was the early preview, July 2025 was the full launch, and November 2025 is when the monthly reminders start. From 1 November 2025, a project restored from a pause is no longer restored with the legacy API keys, and a new project no longer has anon and service_role available, so a restored project can already be broken. Late 2026, TBC, the legacy API keys will be deleted and removed from the Docs / Dashboard. You have to migrate by then or the app will break. No exact day has been published. The migration guide is where a straight swap fails. pg_net calls and Database Webhooks usually send service_role on an Authorization: Bearer header. A new secret key is not a JWT, so that header rejects it. Send the secret key on the apikey header instead, and store it in Vault. Do not hardcode it in SQL or in the webhook config. Edge Functions get new environment variables, SUPABASE_PUBLISHABLE_KEYS and SUPABASE_SECRET_KEYS, and each one is a JSON object keyed by name. The default secret is JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']. SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY still carry the legacy keys. Send a publishable key or a secret key on the apikey header only. Passing one of them on Authorization: Bearer makes the platform try to parse a JWT and reject the call with Invalid JWT, unless that header value exactly matches the apikey header. The built-in verify_jwt check only understands the legacy JWT keys, so a function called with the new keys needs verify_jwt = false and an authorization check in the function's own code, or npm:@supabase/server with withSupabase({ auth: 'user' | 'secret' }). Passing verify_jwt does not authenticate a caller who only sends an API key. A public Realtime connection with no signed-in user, or one that uses a secret key, lasts at most 24 hours. There is no automatic usage indicator. Step 5 of the migration guide says to check every place that holds a key, including mobile and desktop versions already in users' hands, CI/CD and deploy scripts, third-party integrations and webhooks, cron jobs, workers, and pg_net or Database Webhooks. Step 6 is to deactivate the legacy keys in Settings > API Keys, and that step is reversible: re-activate them if a client was missed. The env names in the docs are NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY set to a value that begins with sb_publishable_ for the browser-safe publishable key, and SUPABASE_SECRET_KEY set to a value that begins with sb_secret_ for the secret key. The secret key is server only. Never prefix it with NEXT_PUBLIC_ or VITE_.
Before and after
The before line reads the legacy anon key, a long JWT that begins with eyJ, from NEXT_PUBLIC_SUPABASE_ANON_KEY. The after line reads the publishable key, a short string that begins with sb_publishable_, from NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY. The secret key that replaces service_role belongs in SUPABASE_SECRET_KEY, with no NEXT_PUBLIC_ or VITE_ prefix, and it does not belong in this browser client. Do not paste a real key into either line.
Before
createClient(url, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY)
After
createClient(url, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY)
Fix prompt
In this project only. Do not scan or test anyone else's app. Do not print key values, tokens, passwords, or environment variable values. When you report a key, give the file, the variable name, and whether it is legacy or new. Do not print the value.
1. Find every Supabase key usage in this project. Search createClient calls, .env files, NEXT_PUBLIC_ variables, VITE_ variables, Edge Functions, SQL, pg_net, Database Webhooks, and CI or deploy scripts. A legacy key is a value that is a JWT beginning with eyJ, or a variable named SUPABASE_ANON_KEY or SUPABASE_SERVICE_ROLE_KEY, including NEXT_PUBLIC_SUPABASE_ANON_KEY. A new key is a publishable key beginning with sb_publishable_, a secret key beginning with sb_secret_, or a read of SUPABASE_PUBLISHABLE_KEYS or SUPABASE_SECRET_KEYS. List each hit and say legacy or new.
2. If this project has no publishable key and no secret key, tell me to create them. I do that in the Supabase dashboard under Settings > API Keys, on the Publishable and secret API keys tab, with the Create new API keys button. Older projects that are still on legacy keys only show that button. The new keys are named default. You cannot create the keys. Do not invent a key. Wait until I say the keys exist before you tell me to deploy.
3. Swap this project's client code to the publishable key. Read it from an env var such as NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY. That value is browser-safe. Do not hardcode it. Show me the diff.
4. Swap this project's server code, workers, and other backend clients to the secret key. Read it from a server-only env var such as SUPABASE_SECRET_KEY. Never prefix that name with NEXT_PUBLIC_ or VITE_. Never put the secret key in browser code, a client component, or a public env var. Show me the diff.
5. Find every place that sends a Supabase key on an Authorization: Bearer header. Publishable and secret keys are not JWTs. Sending one there makes the platform try to parse a JWT and reject the call with Invalid JWT, unless that header's value exactly matches the apikey header. Change those calls so the publishable or secret key is sent on the apikey header only. Leave Authorization: Bearer for a signed-in user's own JWT. Show me the diff.
6. For Edge Functions in this project, read the key from the JSON env var. The default secret is JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']. SUPABASE_PUBLISHABLE_KEYS is the same kind of JSON object. SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY still carry the legacy keys. Or use npm:@supabase/server with withSupabase({ auth: 'user' | 'secret' }). Send the new keys on the apikey header only. The built-in verify_jwt check only understands legacy JWT keys. Set verify_jwt = false only on a function that authorizes the caller in its own code. Passing verify_jwt does not authenticate a caller who only sends an API key. Show me the diff.
7. For pg_net calls and Database Webhooks in this project, stop sending the key on Authorization: Bearer. A new secret key is not a JWT, so that header rejects it. Send the secret key on the apikey header, and store it in Vault. Do not hardcode it in SQL or in the webhook config. Show me the diff.
8. List the places I have to update by hand. Do not edit them from here. Include this project's hosting env vars, mobile and desktop builds already in users' hands, CI/CD and deploy scripts, third-party integrations and webhooks, cron jobs, and workers. There is no automatic usage indicator, so the list has to come from what you found in step 1 plus these places.
9. Do not deactivate the legacy keys. After every client in this project is switched, tell me to deactivate them myself in Settings > API Keys. Deactivating is reversible. I can re-activate a legacy key if something still needs it.
Do not print keys. Do not edit unrelated files.Paste this into the coding tool that has your own project open.
2-minute self-check
These steps are for an app you own. Do not run them against someone else's project.
- In your own Supabase project, open Settings > API Keys and look at the Publishable and secret API keys tab. A Create new API keys button means the project is still on legacy keys only. The new keys are named default. Do not open anyone else's project.
- In your own repo, and in your own hosting env vars, search for values that start with eyJ and for the names SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY. Those are the legacy keys. Do not paste the values anywhere.
- On your own deployed site, open DevTools, then the Network tab, and select a request to your own project host, the URL that ends in .supabase.co. The apikey header should start with sb_publishable_. It should not start with sb_secret_, and it should not be a service_role key.
- After your own app is switched, deactivate the legacy keys in Settings > API Keys and test sign-in, a data read, a webhook, and an Edge Function on that app. If something breaks, re-activate the legacy keys. That step is reversible. Do not test anyone else's project.
Common questions
The app still works. Why switch the keys before they stop?
Creating the new keys does not turn the legacy keys off. Both work at the same time, so the app can keep running while you move one client at a time. Supabase's docs say the anon and service_role keys are being deprecated by the end of 2026. The announcement in GitHub discussion #29260 says that late 2026, TBC, those keys will be deleted and removed from the Docs / Dashboard, and the app breaks if you have not migrated. No exact day has been published. A project restored from a pause from 1 November 2025 already comes back without the legacy keys, so that restore can break the app before the late 2026 deletion.
I created publishable and secret keys. Can I turn off the anon key now?
Not until every client has moved. Step 6 of the migration guide is to deactivate the legacy keys in Settings > API Keys, and that step is reversible: re-activate them if a client was missed. There is no automatic usage indicator. Check mobile and desktop versions already in users' hands, CI/CD and deploy scripts, third-party integrations and webhooks, cron jobs, workers, and pg_net or Database Webhooks before you deactivate. The publishable key replaces anon and is the one browsers should send. The secret key replaces service_role, bypasses RLS, and returns HTTP 401 from a browser. Keep the secret key in a server-only env var, and do not prefix it with NEXT_PUBLIC_ or VITE_.
My Edge Function says Invalid JWT after I pasted the new key. Is the key wrong?
Publishable and secret keys are short strings, not JWTs. Sending one on Authorization: Bearer makes the platform try to parse a JWT and reject the call with Invalid JWT, unless that value exactly matches the apikey header. Send the new key on the apikey header only. The built-in verify_jwt check only understands the legacy JWT keys, so set verify_jwt = false on a function that authorizes the caller in its own code, or use npm:@supabase/server with withSupabase({ auth: 'user' | 'secret' }). Passing verify_jwt does not authenticate a caller who only sends an API key. On an Edge Function, SUPABASE_PUBLISHABLE_KEYS and SUPABASE_SECRET_KEYS are JSON objects keyed by name. The default secret is JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']. SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY still hold the legacy keys. pg_net and Database Webhooks have the same Bearer problem: send the secret key on the apikey header and store it in Vault, not hardcoded in SQL or in the webhook config.