If your app talks to Supabase, it sends an API key with every request. For years that key was one of two long tokens beginning with eyJ: the anon key for the browser and the service_role key for servers. Supabase is replacing both with a publishable key (sb_publishable_...) and secret keys (sb_secret_...), and the dashboard now shows a notice that the old pair is on its way out.
Nothing breaks the moment you read that notice. Things break later, when the legacy keys are switched off and a part of the app you forgot about still holds one. An AI builder can put keys in all of these places at once: a client file, a .env file, host settings, Edge Function code, a cron job’s SQL and a Database Webhook. This guide walks through finding all of them, swapping them in a safe order, and reading the errors if something was missed. Our Supabase, Lovable, Bolt and v0 tool pages list more guides for each of those platforms, and the steps below apply to apps built with any of them.
What’s changing, and when
Supabase now has two key systems that run side by side (Supabase: API keys):
| Legacy key | Format | New replacement | Where it belongs |
|---|---|---|---|
anon | Long JWT, starts with eyJ | Publishable key, sb_publishable_... | Browser, mobile app, anything you ship |
service_role | Long JWT, starts with eyJ | Secret key, sb_secret_... | Servers, Edge Functions, cron jobs |
The new keys are short strings and aren’t JWTs. Permissions map across directly: the publishable key acts as the anon Postgres role (or authenticated once a user signs in), and a secret key acts as service_role, which skips Row Level Security.
On timing, Supabase has published three things:
- The docs and the dashboard say early 2027. The API keys page and the migration guide both state that
anonandservice_roleare being deprecated in early 2027. Until late November 2026 the docs said “by the end of 2026”. A pull request merged on 25 November 2026 moved the docs to the early-2027 wording so they match the notice in the dashboard’s Settings > API Keys page (supabase/supabase PR #54052). - The original timetable says apps on legacy keys will break. Supabase’s announcement on GitHub (discussion #29260) has a final row, still labelled “Late 2026, TBC” when we checked on 2 December 2026, saying the legacy keys will be deleted from the dashboard and docs and that any app still relying on them at that point will break.
- Restored projects already lose them. The same timetable says projects restored from 1 November 2025 onward come back without the legacy keys, and that new projects from that month no longer get
anonandservice_roleto use.
No exact switch-off date has been announced, so treat early 2027 as the deadline and check your dashboard banner for updates.
Is your app on legacy keys?
Look at the key value, not the variable name. A legacy key is a long string beginning with eyJ; Supabase’s docs add that when a tutorial or AI assistant has you paste in a long eyJ... key, it is following the old system.
Variable names can mislead you. Lovable’s own instructions for pointing a project at a new Supabase backend use a variable called VITE_SUPABASE_PUBLISHABLE_KEY while showing an anon key as its value (Lovable: Deploying and hosting outside Lovable). So a project can have “publishable” in the name and a legacy eyJ value inside. Older code may use SUPABASE_ANON_KEY, NEXT_PUBLIC_SUPABASE_ANON_KEY or SUPABASE_SERVICE_ROLE_KEY instead.
One thing that is not a problem: a user’s session token also starts with eyJ. If a request made after sign-in carries one in Authorization, that is the user’s login, and it stays a JWT after the migration. The project key you are replacing is the one on the apikey header (a Supabase client may also copy it into Authorization when nobody is signed in), or the one hard-coded where the client is created.
Who holds the keys: Lovable Cloud, Bolt Database or your own Supabase project
Before you change anything, work out who manages the backend.
- Your own Supabase project (you log in at supabase.com and see the project there): you own the migration. Everything below applies.
- Lovable Cloud (the built-in backend): Lovable runs the backend for you and puts the database, users, storage, edge functions and secrets under the project’s More menu (Lovable: Cloud). When we checked on 2 December 2026, Lovable’s Cloud docs said nothing about this key change. Because Lovable runs that backend, ask Lovable’s support how they are handling it before you edit the keys in
.env. - Bolt Database: Bolt fills in the database address and public key in
.envitself and locks those entries so they can’t be edited by hand (Bolt: Secrets). Its automaticSUPABASE_secrets for server functions can’t be deleted either. Ask Bolt before overriding any of them. - Lovable or Bolt connected to your own Supabase account (Lovable: Connect to Supabase, Bolt: Supabase for databases): the keys live in your Supabase project, so you do the migration, then update the code the builder generated.
- v0 or a hand-written Next.js app on Vercel: the keys sit in your Vercel environment variables and your code, so the migration is yours. Supabase’s Vercel Marketplace integration adds
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYandSUPABASE_SECRET_KEYamong its variables (Supabase: Vercel Marketplace), so check whether each variable in your project holds ansb_value or aneyJone.
Where legacy keys hide in an AI-built app
Supabase’s migration guide warns that it has no automatic usage indicator, so you have to check every caller yourself (Supabase: Migrating to new API keys). Make a list using this table before you change a single value:
| Place | What to look for | Replace with |
|---|---|---|
The file that calls createClient (src/integrations/supabase/client.ts, lib/supabase.ts or similar) | An eyJ... string pasted straight into the code | Publishable key, read from an env variable |
.env, .env.local, .env.production | VITE_ or NEXT_PUBLIC_ variables holding eyJ... | Publishable key |
| Host settings (Vercel, Netlify, Cloudflare, Render) | The same variables, set per environment: Production, Preview, Development | Publishable key in public variables, secret key in server-only ones |
| Server code (API routes, server actions, a Node or Python backend) | SUPABASE_SERVICE_ROLE_KEY or a pasted eyJ... | Secret key |
| Edge Functions | Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') or 'SUPABASE_ANON_KEY' | SUPABASE_SECRET_KEYS or SUPABASE_PUBLISHABLE_KEYS |
SQL: pg_net calls, pg_cron jobs, triggers | 'Authorization', 'Bearer eyJ...' inside net.http_post | Secret key sent as apikey, stored in Vault |
| Webhooks set up under Database > Webhooks | Authorization carrying the service_role key | An apikey entry holding a secret key |
| CI and scripts | GitHub Actions secrets, seed scripts, test fixtures | The matching new key |
| Other services | Zapier, Make or n8n steps, a second app on the same project | The matching new key |
| Shipped mobile builds | App store versions with the key compiled in | Publishable key in a new release |
To search the code, run these from the project folder (or ask the AI tool to run them; there’s a prompt for that at the end):
grep -rn "eyJ" --exclude-dir=node_modules --exclude-dir=.git .
grep -rnE "ANON_KEY|SERVICE_ROLE|anon_key|service_role" --exclude-dir=node_modules --exclude-dir=.git .
grep can’t see outside the repo, so also check your host’s environment variables, Edge Function secrets, Database > Webhooks and your cron jobs (Step 5).
On the live site, search the loaded scripts in the browser’s developer tools for eyJ. Open each long match: if it is your project’s anon key, you shipped a legacy key.
Step 1: Create the new keys
In the dashboard, open Settings > API Keys, then switch to the tab listing the new key types. If it offers to Create new API keys, the project only has legacy keys so far. Creating the new ones is harmless: you get one key of each new type, both named default, and the legacy keys keep working alongside them (Supabase: Migrating to new API keys).
Later you can give each backend service its own secret key, so a leak means replacing only that one. For now the two default keys are enough.
Step 2: Put the publishable key in the frontend, then rebuild
Replace the anon key with the publishable key wherever the browser client is created:
import { createClient } from '@supabase/supabase-js'
export const supabase = createClient(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY // now sb_publishable_..., was eyJ...
)
Your Row Level Security policies don’t need to change. Requests made with the publishable key run as anon before sign-in and authenticated after, exactly as they did with the old key, and Supabase Auth logins work as before.
Then rebuild. VITE_ and NEXT_PUBLIC_ values are copied into the JavaScript bundle when the app is built, so editing the variable on your host does nothing until the next build (Next.js: Environment variables; Lovable’s hosting guide says the same for its projects). If you set variables per environment, update Preview as well as Production. The env variables guide covers redeploying on Vercel and Netlify.
Test sign-in, a read and a write on the live site before moving on.
Step 3: Move servers to a secret key
Anywhere server code uses service_role, switch to a secret key:
import { createClient } from '@supabase/supabase-js'
const supabaseAdmin = createClient(
process.env.SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY! // sb_secret_..., server only
)
Two rules for this variable:
- Never give it a public prefix. A
VITE_orNEXT_PUBLIC_name ships the value to every visitor. A secret key also refuses to work from a browser: Supabase checks theUser-Agentheader and answers with HTTP 401 (Supabase: API keys). If an admin page suddenly returns 401 after the swap, one cause to check is that the page calls Supabase with elevated rights from the browser; that logic needs to move to a server route or an Edge Function. - Keep it out of git and out of chat. Put it in your host’s secret settings only.
If a key was already exposed somewhere public, this is a different job: start with the leaked API key guide, because a leaked key has to be retired, not just replaced at your own pace.
Step 4: Update Edge Functions
Supabase injects two new variables into every function, SUPABASE_PUBLISHABLE_KEYS and SUPABASE_SECRET_KEYS, next to the legacy SUPABASE_SERVICE_ROLE_KEY and SUPABASE_ANON_KEY, which hold the old eyJ keys (Supabase: Environment variables). The new ones are JSON objects keyed by key name, so the smallest change looks like this:
// old: a plain string holding the legacy service_role key
const secretKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
// new: parse the JSON and pick the key named "default"
const secretKey = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']
Header handling changes too. Send the new keys in apikey and nowhere else. When a caller also puts one in Authorization: Bearer, Supabase’s migration guide says the platform treats it as a JWT and refuses the call with Invalid JWT. Its Authorization headers reference describes it differently: the verify_jwt check still lets API keys through in that header, but they are not JWTs, so your code cannot validate them that way. The two pages disagree on what the platform does, yet both say to use apikey. The migration guide also says the platform’s verify_jwt check was built for the legacy, JWT-style keys. For a function whose callers prove themselves with an API key rather than a signed-in user, set verify_jwt = false and authorize the key in your own code (Supabase: Migrating to new API keys; Supabase: Authorization headers):
In supabase/config.toml:
[functions.send-digest]
verify_jwt = false
Switching the gate off with nothing in its place means anyone can call the function. Supabase’s recommended way to add the check is the @supabase/server SDK: wrap the handler in withSupabase({ auth: 'secret' }) for functions your backend, cron jobs or pg_net call, or withSupabase({ auth: 'user' }) for functions your signed-in users call (Supabase: Securing Edge Functions). One detail to note: plain auth: 'secret' checks against the default key alone, so a secret key you named something else needs auth: 'secret:that-name'.
Change, deploy and test one function at a time; migrating a duplicate first is a safe trial. If a function starts returning 401 or 500 after this step, the Edge Function non-2xx guide shows how to read the actual error from the logs.
Step 5: Database Webhooks and pg_net
This key isn’t in your app’s code at all; it lives inside the database, which makes it easy to forget.
SQL written for the old keys, including dashboard webhooks and hand-written pg_net calls, puts the service_role JWT in Authorization: Bearer. A secret key in that header is rejected, since it isn’t a JWT. Send it as apikey instead, and pull it from Vault instead of typing it into the SQL (Supabase: Migrating to new API keys; Supabase: Database Webhooks):
-- store the key once
select vault.create_secret('sb_secret_...', 'secret_key');
-- then, in the job or trigger function
select net.http_post(
url := 'https://your-project-ref.supabase.co/functions/v1/send-digest',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'apikey', (select decrypted_secret from vault.decrypted_secrets where name = 'secret_key')
),
body := jsonb_build_object('source', 'cron')
);
Open Database > Webhooks and, for every webhook listed there, edit its HTTP headers: remove the Authorization entry carrying the old key, then add an apikey entry whose value is the secret key. The webhook form’s Add secret key option under HTTP Headers does this, though the key is then stored inside the webhook’s trigger and shows up in a dump of the database’s SQL (Supabase: Database Webhooks).
For cron jobs, run select jobname, command from cron.job; and look for Bearer eyJ in the output. After you change a job, confirm the next run worked by checking net._http_response for a 2xx status. The cron job guide has the full query and the Vault setup for scheduled calls.
Step 6: Check every caller by hand, then deactivate the legacy keys
Go back to the list you made from the table above and tick off each place. Supabase’s migration guide names the callers it expects you to miss: app versions already installed on users’ phones or desktops, CI pipelines and deploy scripts, third-party integrations, plus workers, scheduled jobs, webhooks and anything in SQL that calls pg_net.
Mobile apps need lead time: a new release doesn’t reach phones that haven’t installed it, and store review takes time. Ship it well before you deactivate anything.
When the list is complete, open Settings > API Keys and deactivate the legacy keys. This is reversible: if something you missed starts failing, you can turn them back on, fix that caller, and turn them off again (Supabase: Migrating to new API keys). A sensible way to do it:
- Deactivate at a quiet hour, with the dashboard open.
- Test sign-in, reads, writes, uploads, every Edge Function and one run of each cron job.
- Watch the API, Edge Function and
net._http_responselogs for an hour. - If something fails and can’t be fixed quickly, re-enable, fix that caller, and retry another day.
The one exception: if you are deactivating because a key leaked, don’t re-enable them, since that switches the leaked key back on too. Supabase’s leaked-key procedure says to move the missed client to a new key instead (Supabase: Rotating leaked API keys).
Once the API keys are done, Supabase suggests a separate, optional follow-up: moving user tokens from the shared legacy JWT secret to JWT signing keys (Supabase: JWT signing keys). Don’t do both at once.
“Legacy API keys are disabled” and other errors after the switch
| Error | What it means | Fix |
|---|---|---|
Legacy API keys are disabled | Something sent an eyJ legacy key to a project where the legacy keys are switched off. The hint in the response names the time they were disabled and suggests re-enabling them or using the new keys (supabase/cli #3893). | Find that caller with the table above and give it the publishable or secret key. Compare the timestamp in the hint with your recent deploys to see what changed. |
Invalid JWT from an Edge Function | Per Supabase’s migration guide, a publishable or secret key sent as Authorization: Bearer is treated as a JWT and refused (the Authorization headers reference describes it differently; see Step 4). | Send it as apikey alone, and set verify_jwt = false with a check in code (Step 4). |
PGRST301 with “Expected 3 parts in JWT; got 1” | A client put the new key in the Authorization header and PostgREST could not decode it as a JWT. In the reported case, a Supabase maintainer traced it to the local CLI and said a newer CLI release fixed it (supabase-py #1230). | Update the Supabase CLI and your Supabase client library, and make sure no custom code sets Authorization to the API key. |
| HTTP 401 on a page that used to work | A secret key may be in use from a browser; Supabase blocks that by User-Agent. | Move that call to a server or Edge Function. Don’t put the secret key in the frontend. |
401 on GET /rest/v1/ with the publishable key | That root route only accepts secret keys, even though table routes accept the publishable key (Supabase: API keys). | Point uptime checks at /auth/v1/health or at one of your table routes. |
One related case: Supabase’s timetable says a project restored from a pause since 1 November 2025 comes back without the legacy keys, so an app still holding an eyJ key after a restore has nothing to re-enable. Do the migration from Step 1. The paused project guide has the other checks to run after a restore.
A prompt to find every key in your project
Paste this into the AI tool that generated your app (Lovable, Bolt, v0, Cursor and so on). It asks for a report first, so nothing changes until you’ve read it:
Do not change any code yet. Find every place this project uses a Supabase API key and list them in a table with: file path and line, variable name, whether the value is a legacy key (starts with "eyJ") or a new key (starts with "sb_publishable_" or "sb_secret_"), whether that code runs in the browser or on a server, and which header the key is sent on (apikey or Authorization).
Include: the createClient call(s), every .env file, server routes, Edge Functions (look for SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, SUPABASE_PUBLISHABLE_KEYS, SUPABASE_SECRET_KEYS), SQL migrations or functions that call net.http_post, cron job definitions, and test or seed scripts.
Flag as urgent any service_role or sb_secret_ value found in code that runs in the browser, or in any variable named with VITE_ or NEXT_PUBLIC_.
Then list the places outside the code I need to check myself (host environment variables, Edge Function secrets, Database Webhooks, cron jobs, other services).
Then approve changes one area at a time, in the order of the steps above, testing after each. Don’t let the tool paste a secret key into any file it creates; enter those values yourself in the secret settings of your host or of Supabase.
FAQ
Is the publishable key safe to put in my frontend?
Yes. Supabase designed it to ship in web and mobile clients, just like the anon key it replaces, and it gets no more access than your Row Level Security policies allow for anon and authenticated. That also means it protects nothing by itself: anyone can copy it from your site. Make sure RLS is on for every table. The leaked-key guide lists which keys are public and which never are.
Will my app break if I do nothing?
Not today: legacy keys work until they are deactivated. But the docs give early 2027 for the deprecation, the timetable says apps still on legacy keys break once those keys are deleted, and restored projects already come back without them. With no exact date announced, aim to finish well before early 2027.
Why does my new secret key fail with a JWT error?
Because it isn’t a JWT. Something is putting it in Authorization: Bearer, where only JWTs belong: a pg_net call or webhook copied from an old example, function code that tries to verify that header as a JWT, or an outdated Supabase CLI. Move the key to apikey, update your Supabase tools, and see Steps 4 and 5.
Do I need to change anything in Lovable Cloud?
Lovable’s docs didn’t cover this change for the built-in backend when we checked on 2 December 2026. Ask Lovable’s support before editing the generated keys. If you linked the project to a Supabase account you own, the steps above apply.
Can I switch back if something breaks?
Yes, while the legacy keys still exist: deactivation can be undone in Settings > API Keys. Don’t re-enable keys that were turned off because one leaked, and once Supabase deletes the legacy keys there is nothing to switch back to.
Comments