← All errors · Supabase

Supabase "Legacy API keys are disabled": migrate anon and service_role keys to publishable and secret keys

What you see

Requests from your app to Supabase start failing after the legacy anon or service_role key is turned off, and the app loses database access. Third-party guides and user reports quote the error as "Legacy API keys are disabled". Supabase's own docs do not quote this exact text, so treat the wording as reported, not official. Any app still sending a long key that starts with eyJ is using a legacy key.

What it means

Supabase is deprecating the legacy anon and service_role keys by the end of 2026. The exact date they stop working has not been announced yet (TBC as of Nov 3, 2026), so do not plan around a specific day. The replacements are the publishable key (sb_publishable_...), which replaces anon, and the secret key (sb_secret_...), which replaces service_role. The legacy keys are long-lived JWTs that start with eyJ; the new keys are short strings, not JWTs. Both key types work at the same time, so you can switch one client at a time and turn the legacy keys off only when nothing uses them. Creating the new keys does not revoke the old ones. Deactivating legacy keys in Settings > API Keys is reversible: you can re-activate them if you missed a client. The publishable key has the same low privileges as anon, so Row Level Security behaves the same and Supabase Auth sign-in is unchanged. Secret keys bypass RLS like service_role, but return HTTP 401 if used from a browser. Is my app affected? (2-minute check) 1) Spot a legacy key: search for a long string starting with eyJ. If a tutorial, tool or AI assistant told you to copy an eyJ key, it was written for legacy keys. A variable name is not proof: a variable called SUPABASE_PUBLISHABLE_KEY can still hold an eyJ value, so check the value itself. 2) Where to look: .env, .env.local and .env.production files; environment variables on Vercel, Netlify or your host; the Supabase client file in your code (in Lovable projects usually src/integrations/supabase/client.ts); Edge Function code that reads SUPABASE_ANON_KEY or SUPABASE_SERVICE_ROLE_KEY; Database Webhooks and pg_net calls; CI/CD scripts, cron jobs and third-party integrations; mobile or desktop app versions already in users' hands. 3) Browser vs server: anon becomes the publishable key in browser and public code. service_role becomes a secret key on the server only. Never put a secret key in browser code, a VITE_ or NEXT_PUBLIC_ variable, or source control. 4) Build-time variables: VITE_ and NEXT_PUBLIC_ variables are baked into the bundle when the app is built. Changing them in your host does nothing until you rebuild and redeploy. 5) Lovable Cloud: if your Supabase backend is managed by Lovable Cloud (you never created a Supabase project yourself), ask Lovable support how keys are being migrated for your project before you rotate or disable anything yourself.

Likely causes

How to fix it

  1. Find every legacy key. Search your code and env files for values starting with eyJ, then check your host's environment variables (Vercel, Netlify and so on) by hand:

    grep -rnE "eyJ[A-Za-z0-9_-]{20,}" --exclude-dir=node_modules --exclude-dir=.git .
    grep -rnE "SUPABASE_(ANON|SERVICE_ROLE)_KEY|anon[_-]?key|service[_-]?role" --exclude-dir=node_modules --exclude-dir=.git .
  2. If your Supabase is managed by Lovable Cloud, stop here and ask Lovable support how to migrate. Only follow the next steps if you own the Supabase project.

  3. Create the new keys: Supabase Dashboard > Settings > API Keys > "Publishable and secret API keys" tab. If you see a "Create new API keys" button, click it. This adds a publishable key and a secret key named default next to your legacy keys; the legacy keys keep working.

  4. Browser and public code: replace the anon key with the publishable key. RLS and Supabase Auth behave the same.

    import { createClient } from '@supabase/supabase-js'
    
    const supabase = createClient(
      import.meta.env.VITE_SUPABASE_URL,
      import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY // sb_publishable_..., was the anon key
    )
  5. Server code only: replace the service_role key with a secret key. Keep it in a server-only env var (no VITE_ or NEXT_PUBLIC_ prefix). It bypasses RLS, and Supabase returns 401 if a secret key is used from a browser.

    import { createClient } from '@supabase/supabase-js'
    
    const supabaseAdmin = createClient(
      process.env.SUPABASE_URL,
      process.env.SUPABASE_SECRET_KEY // sb_secret_..., was the service_role key
    )
  6. Edge Functions: read the new keys from SUPABASE_SECRET_KEYS or SUPABASE_PUBLISHABLE_KEYS. They hold JSON keyed by name, and the first key is named default. Send these keys in the apikey header, not Authorization: Bearer, and set verify_jwt = false for functions that receive them, then authorize the request in your own code (or use the @supabase/server SDK).

    // before
    const secretKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
    
    // after
    const secretKey = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']
  7. Database Webhooks and pg_net: the new secret key is not a JWT, so it is rejected in Authorization: Bearer. Remove that header and send the key in an apikey header instead. Store the key in Supabase Vault rather than pasting it into SQL or the webhook config:

    headers := jsonb_build_object(
      'Content-Type', 'application/json',
      'apikey', (select decrypted_secret from vault.decrypted_secrets where name = 'secret_key')
    )
  8. Update the env vars in your host, then rebuild and redeploy. VITE_ and NEXT_PUBLIC_ values are baked in at build time, so the live site keeps the old key until a new build ships.

  9. Test it: open the deployed site, sign in and load a page that reads data. In DevTools > Network, open a request to your-project.supabase.co and check that the apikey header starts with sb_publishable_, not eyJ. Search the built bundle for leftovers:

    npm run build
    grep -rl "eyJ" dist .next/static 2>/dev/null || echo "no eyJ keys in the build"
  10. When nothing uses the legacy keys, deactivate them in Settings > API Keys. Supabase has no automatic usage indicator, so watch your app and logs afterward. If something breaks, you can re-activate the legacy keys, fix that caller, and try again.

Still stuck after trying this? Get it fixed for $49, or you don't pay.

FAQ

What does "Supabase "Legacy API keys are disabled": migrate anon and service_role keys to publishable and secret keys" mean?

Supabase is deprecating the legacy anon and service_role keys by the end of 2026. The exact date they stop working has not been announced yet (TBC as of Nov 3, 2026), so do not plan around a specific day. The replacements are the publishable key (sb_publishable_...), which replaces anon, and the secret key (sb_secret_...), which replaces service_role. The legacy keys are long-lived JWTs that start with eyJ; the new keys are short strings, not JWTs. Both key types work at the same time, so you can switch one client at a time and turn the legacy keys off only when nothing uses them. Creating the new keys does not revoke the old ones. Deactivating legacy keys in Settings > API Keys is reversible: you can re-activate them if you missed a client. The publishable key has the same low privileges as anon, so Row Level Security behaves the same and Supabase Auth sign-in is unchanged. Secret keys bypass RLS like service_role, but return HTTP 401 if used from a browser. Is my app affected? (2-minute check) 1) Spot a legacy key: search for a long string starting with eyJ. If a tutorial, tool or AI assistant told you to copy an eyJ key, it was written for legacy keys. A variable name is not proof: a variable called SUPABASE_PUBLISHABLE_KEY can still hold an eyJ value, so check the value itself. 2) Where to look: .env, .env.local and .env.production files; environment variables on Vercel, Netlify or your host; the Supabase client file in your code (in Lovable projects usually src/integrations/supabase/client.ts); Edge Function code that reads SUPABASE_ANON_KEY or SUPABASE_SERVICE_ROLE_KEY; Database Webhooks and pg_net calls; CI/CD scripts, cron jobs and third-party integrations; mobile or desktop app versions already in users' hands. 3) Browser vs server: anon becomes the publishable key in browser and public code. service_role becomes a secret key on the server only. Never put a secret key in browser code, a VITE_ or NEXT_PUBLIC_ variable, or source control. 4) Build-time variables: VITE_ and NEXT_PUBLIC_ variables are baked into the bundle when the app is built. Changing them in your host does nothing until you rebuild and redeploy. 5) Lovable Cloud: if your Supabase backend is managed by Lovable Cloud (you never created a Supabase project yourself), ask Lovable support how keys are being migrated for your project before you rotate or disable anything yourself.

What usually causes it?

The legacy anon or service_role key (an eyJ... JWT) was deactivated, either by you in Settings > API Keys or when Supabase retires legacy keys (by the end of 2026, exact date TBC). The browser bundle still holds the old anon key because a VITE_ or NEXT_PUBLIC_ variable was changed but the app was not rebuilt and redeployed. A variable named like a new key (for example SUPABASE_PUBLISHABLE_KEY) still holds an old eyJ value. An Edge Function still reads SUPABASE_ANON_KEY or SUPABASE_SERVICE_ROLE_KEY, which carry the legacy keys. A Database Webhook or pg_net call still sends the service_role key in the Authorization: Bearer header. An easy-to-miss caller still uses the old key: a cron job, CI/CD script, third-party integration, or an old mobile or desktop app version.

How do I fix it?

1. Find every legacy key. Search your code and env files for values starting with eyJ, then check your host's environment variables (Vercel, Netlify and so on) by hand: 2. If your Supabase is managed by Lovable Cloud, stop here and ask Lovable support how to migrate. Only follow the next steps if you own the Supabase project. 3. Create the new keys: Supabase Dashboard > Settings > API Keys > "Publishable and secret API keys" tab. If you see a "Create new API keys" button, click it. This adds a publishable key and a secret key named default next to your legacy keys; the legacy keys keep working. 4. Browser and public code: replace the anon key with the publishable key. RLS and Supabase Auth behave the same. 5. Server code only: replace the service_role key with a secret key. Keep it in a server-only env var (no VITE_ or NEXT_PUBLIC_ prefix). It bypasses RLS, and Supabase returns 401 if a secret key is used from a browser. 6. Edge Functions: read the new keys from SUPABASE_SECRET_KEYS or SUPABASE_PUBLISHABLE_KEYS. They hold JSON keyed by name, and the first key is named default. Send these keys in the apikey header, not Authorization: Bearer, and set verify_jwt = false for functions that receive them, then authorize the request in your own code (or use the @supabase/server SDK). 7. Database Webhooks and pg_net: the new secret key is not a JWT, so it is rejected in Authorization: Bearer. Remove that header and send the key in an apikey header instead. Store the key in Supabase Vault rather than pasting it into SQL or the webhook config: 8. Update the env vars in your host, then rebuild and redeploy. VITE_ and NEXT_PUBLIC_ values are baked in at build time, so the live site keeps the old key until a new build ships. 9. Test it: open the deployed site, sign in and load a page that reads data. In DevTools > Network, open a request to your-project.supabase.co and check that the apikey header starts with sb_publishable_, not eyJ. Search the built bundle for leftovers: 10. When nothing uses the legacy keys, deactivate them in Settings > API Keys. Supabase has no automatic usage indicator, so watch your app and logs afterward. If something breaks, you can re-activate the legacy keys, fix that caller, and try again.

Last checked against official docs on . Sources: Supabase docs: Migrating to publishable and secret API keys, Supabase docs: Understanding API keys, Supabase announcement on GitHub: upcoming changes to API keys.

Related errors

More Supabase errors and fixes →

Tools that help

  • Railway: Deploy backends and databases; new users get $20 credit.

Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.

Get new fixes weekly

No spam. Unsubscribe anytime. Privacy