Keys / Supabase
SUPABASE_SECRET_KEY
The Supabase key your server uses to reach all of a project's data, bypassing Row Level Security. It replaces the legacy service_role key.
- Starts with
sb_secret_- Expires
- no expiry in the docs; it works until you delete it
- API
- create, list and delete, with an access token
Get it
Create one on supabase.com/dashboard/project/_/settings/api-keys. The steps aren't recorded yet.
Set it
SUPABASE_SECRET_KEY=sb_secret_...
@supabase/server reads it when SUPABASE_SECRET_KEYS isn't set; with supabase-js, your app passes it to createClient. Edge Functions get every secret key by name in SUPABASE_SECRET_KEYS. Or keep it out of .env with keypin: keypin run -- npm run dev
Replace it
- Create a new secret key in Settings > API Keys. A project can have several, each with its own name. Every project starts with one named
default;keypin rotaterefuses that one, so give each app its own named key. - Deploy it everywhere that uses the old key.
- An Edge Function that checks
withSupabase({ auth: 'secret' })accepts only the key nameddefault, andauth: 'secret:<name>'only that name. Useauth: 'secret:*'to accept any secret key, so a new key with a new name works, and deploy it. - Check that nothing still uses the old key, then delete it. Deleting a secret key can't be undone.