Upgrade to Supabase's new API keys
Supabase is retiring its legacy API keys, the anon key and the service_role key. Its migration guide and your project's API Keys page give Supabase's current schedule, so migrate by whichever date comes first: Supabase's, or Shelf's 2027-02-18 below. Shelf now supports the keys that replace them: a publishable key (sb_publishable_...) and a secret key (sb_secret_...).
This guide is for anyone running their own Shelf instance. If you use Shelf at shelf.nu, there is nothing to do.
What changes and when
| Setting | Before | After |
|---|---|---|
SUPABASE_ANON_PUBLIC | legacy anon key | publishable key (sb_publishable_...) |
SUPABASE_SECRET_KEY | (did not exist) | secret key (sb_secret_...) |
SUPABASE_SERVICE_ROLE | legacy service_role key | remove it |
Until 2027-02-18, Shelf still accepts
SUPABASE_SERVICE_ROLEwhenSUPABASE_SECRET_KEYis not set. It logs this warning at startup:DEPRECATED CONFIGURATION: SUPABASE_SERVICE_ROLE is set without SUPABASE_SECRET_KEY.Releases after 2027-02-18 require
SUPABASE_SECRET_KEY. An instance still onSUPABASE_SERVICE_ROLEwill not start.No database migration is involved, and no Shelf data changes.
The secret key does one more thing: it lets Shelf tell Supabase who is signing in. Supabase limits sign-in attempts per IP address. Shelf signs people in from its server, so without the secret key Supabase counts every visitor against your server's address. See Per-visitor sign-in limits.
Upgrade steps
Get the keys. In your Supabase project, open Project Settings → API Keys.
- Copy the publishable key (
sb_publishable_...). - Under Secret keys, create a key if there is none, then copy it (
sb_secret_...). Treat it like a password: it has full access to your project.
On a local Supabase started with the CLI, run
supabase statusinstead. It prints both keys. If it shows nosb_secret_...key, update the Supabase CLI.- Copy the publishable key (
Update your environment. Use the keys from the same Supabase project that
SUPABASE_URLpoints at:bashSUPABASE_URL="https://your-project-ref.supabase.co" SUPABASE_ANON_PUBLIC="sb_publishable_..." SUPABASE_SECRET_KEY="sb_secret_..." # SUPABASE_SERVICE_ROLE="..." # remove or comment outOn Docker, pass
-e 'SUPABASE_SECRET_KEY=...'(see Docker Setup). On Fly.io, runfly secrets set SUPABASE_SECRET_KEY=... SUPABASE_ANON_PUBLIC=...(see Deployment).Restart Shelf and check that the
DEPRECATED CONFIGURATIONwarning no longer appears in the startup log.Check that it works:
- sign in with a password
- sign in with a one-time email code
- reset a password
- upload an image (a profile picture or an asset image)
- if you use SSO, sign in through
/sso-login, from your identity provider's dashboard, and in the companion app
Per-visitor sign-in limits (optional)
With SUPABASE_SECRET_KEY set, Shelf can send each visitor's IP address to Supabase, so its sign-in limits count each visitor instead of your server. This covers password sign-in, sign-up, one-time codes, password reset, email change, session refresh and SSO.
In Supabase, open Authentication → Rate Limits and turn on IP Address Forwarding.
Tell Shelf where the visitor's IP comes from:
Behind your own reverse proxy (nginx, Caddy, Traefik, and so on): set
TRUSTED_PROXY_HOPSto the number of proxies in front of Shelf that append toX-Forwarded-For, usually1. Shelf reads the entry your outermost proxy added.WARNING
This is only safe when every request reaches Shelf through those proxies. Do not expose the app port (3000 by default) directly: bind it to localhost or a private network, or firewall it. Otherwise a visitor can connect around the proxies and choose the address Shelf reads.
On Fly.io: nothing to set. Shelf reads
Fly-Client-IP.On Fly.io behind Cloudflare:
Fly-Client-IPis then Cloudflare's address. Add a Cloudflare Transform Rule (Rules → Transform Rules → Modify Request Header) that setsX-Shelf-Proxy-Secretto a random value (openssl rand -hex 32) on all incoming requests, and set the same value asCLOUDFLARE_PROXY_SECRET. Shelf then readsCF-Connecting-IP, but only from requests that carry that secret.
Review the limits on the same Rate Limits page. People signing in from one office often share one IP address.
Without IP forwarding, nothing breaks: Supabase keeps counting sign-ins against your server's address, as before.
Troubleshooting
Sign-in fails with "Invalid API key". The key and SUPABASE_URL belong to different Supabase projects. Check the key against the URL directly; 200 means it is valid for that project:
curl -s -o /dev/null -w "%{http_code}\n" "$SUPABASE_URL/auth/v1/settings" -H "apikey: sb_secret_..."Also check that your .env does not define the same variable twice, for example an old commented-in value further down.
The deprecation warning still appears. SUPABASE_SECRET_KEY is not reaching the server. Check the spelling, and restart the server after changing the environment.
Supabase's logs show your server's IP, not the visitor's. Check that IP Address Forwarding is on in Supabase, that SUPABASE_SECRET_KEY is set, and, off Fly.io, that TRUSTED_PROXY_HOPS matches your proxies.
