Supabase keys and connection strings, sorted out

Which Supabase key and which connection string go where, the password you only see once, row level security, auth URLs and free plan pausing.

Simon, Founder of Shipyard

By · Founder of Shipyard

7 minute read

Which value goes where

A Supabase project gives you two API keys and three ways to connect to Postgres, and almost every early problem comes from using the wrong one in the wrong place. The publishable key goes in the browser and is limited by row level security. The secret key stays on your server and bypasses it. Code on a long-running server uses the direct connection or the session pooler; code in serverless functions uses the transaction pooler on port 6543. The tables below give the details, and the sections after them cover the settings that bite in the first week.

KeyLooks likeAllowed inDatabase role
Publishablesb_publishable_...Browser, mobile app, source codeanon, or authenticated once a user signs in. Row level security applies.
Secretsb_secret_...Servers and jobs onlyservice_role, which skips every row level security policy.
Legacy anonA long JWT starting eyJSame as publishableSame as publishable
Legacy service_roleA long JWTSame as secretSame as secret

The two generations of keys

Older tutorials and many AI-generated projects still use the names anon and service_role, with variables such as NEXT_PUBLIC_SUPABASE_ANON_KEY. Those legacy keys still work, and creating the new ones does not revoke them, but Supabase's documentation says it is deprecating both "by the end of 2026". Start a new product on the publishable and secret keys. You find and create them in the dashboard under Settings, API Keys.

The secret key has one protection the old service_role key lacked: if it is used from a browser, Supabase recognises that from the request and answers 401. Treat that as a seat belt, not as permission. A leaked secret key still works from any script, so rotate it if it ever reaches a repository or a client bundle.

Three ways into Postgres

For code that talks to Postgres directly, with Prisma, Drizzle, pg or a migration tool, press Connect at the top of the project page and choose a method. Copy the pooler host from that dialog; it contains a cluster number you cannot guess from the region.

The choice follows from where the code runs. A normal server, such as a Railway service, keeps connections open, so the direct connection is right if the host can reach IPv6, and the session pooler if it cannot. A direct connection that fails with a network error on an otherwise correct string is nearly always an IPv4-only host. Functions on Vercel start and stop constantly, so they need the transaction pooler, which lends a real connection only for the length of one transaction.

Transaction mode has a price. Prepared statements are not supported on the shared pooler, and session state such as set, temporary tables and listen/notify does not behave reliably. Turn prepared statements off in the driver: prepare: false for Postgres.js and Drizzle, pgbouncer=true in a Prisma connection string. In a serverless function, create the client once at module level and keep its pool size at 1. Run migrations over the direct connection or the session pooler, not the transaction pooler.

TypeScript
import postgres from 'postgres';

// transaction pooler (port 6543): prepared statements must be off
const sql = postgres(process.env.DATABASE_URL!, { prepare: false });
MethodHost and portUserNetworkUse for
Directdb.<ref>.supabase.co:5432postgresIPv6, or IPv4 with the IPv4 add-onLong-running servers, migrations, backups
Session pooleraws-...pooler.supabase.com:5432postgres.<ref>IPv4Long-running servers on IPv4-only hosts
Transaction pooleraws-...pooler.supabase.com:6543postgres.<ref>IPv4Serverless and edge functions

The database password is shown once

You set the database password when the project is created, and the dashboard does not show it again. The strings in the Connect dialog contain the placeholder [YOUR-PASSWORD] where it belongs. If you lost it, you can reset it under Database Settings, which breaks every connection still using the old one.

Two practical rules follow. Save the password in a password manager at creation, not in a note. And generate one without characters that have a meaning in a URL: a password containing &, # or ? has to be percent-encoded before it goes into a connection string, and forgetting that produces an authentication error that looks like a wrong password. Shipyard generates the password itself from 24 random bytes in URL-safe base64, keeps it in the keychain on your computer, and still encodes it when filling the placeholder.

Row level security and what the Data API exposes

Supabase puts an HTTP API in front of your tables, the Data API, so a browser holding the publishable key can query them directly. Row level security (RLS) is the Postgres feature that decides which rows each user may see. A table that is reachable through the Data API and has no RLS can be read by anyone with the publishable key, and that key is in your page source.

How a table is created decides its starting state. Tables made in the dashboard's table editor have RLS switched on automatically. Tables made with SQL, by a migration or by an ORM, do not; you switch it on yourself. On existing projects new tables in the public schema are also granted to the API roles automatically, so they are reachable by default. Supabase is changing that default to opt-in, and you can already turn off "Automatically expose new tables" in the Data API settings.

With RLS on and no policy, the publishable key sees nothing, which is a safe place to start. Then add policies for exactly what users should reach. If your app only ever queries from its own server over a connection string, as Shipyard's starter does by default, you can switch the Data API off entirely.

sql
alter table your_table enable row level security;

Auth: the localhost link in your confirmation emails

If you use Supabase Auth, open Authentication, URL Configuration before you send a single sign-up email. Site URL is the address Supabase puts into confirmation and password-reset links when your code does not pass a redirectTo. Its default is http://localhost:3000. A production app that never changed it emails every new user a link to their own computer.

Next to it is the list of additional redirect URLs your code is allowed to ask for. It accepts wildcards, with . and / treated as separators.

Supabase recommends exact URLs in production and wildcards for local and preview use. Shipyard sets Site URL to https://yourdomain and the allow list to https://yourdomain/**, which keeps every redirect on your own domain; tighten it to exact paths once your auth routes are final.

PatternMatchesExample
*Any run of characters that are not separatorshttps://*-<team-or-account-slug>.vercel.app/** for Vercel preview addresses
**Any run of charactershttp://localhost:3000/** matches /foo/bar
?One character that is not a separatorRarely needed

Scripting it with the Management API, and what Shipyard does

Everything above can be scripted against api.supabase.com with a personal access token, created under Account, Access Tokens. Tokens made in the dashboard are now scoped by default: you choose the organisations and projects they cover and grant each permission as Read or Read-write. For this flow the token needs, at the least, Read-write on Organization Projects to create the project, and Read on both API Keys and API Key Secrets; without those two, a request for the key values is refused with a 403. Each endpoint's reference page lists the permission it requires.

Creating the project is one POST to /v1/projects with name, db_pass and organization_slug; the slug is in the dashboard address after /org/. The response contains ref, the 20-character project reference that every later call and every host name uses. The project is not usable yet. Its status moves through COMING_UP to ACTIVE_HEALTHY over a minute or two, so poll /v1/projects/{ref}/health?services=db before reading the pooler configuration or the keys.

With Supabase chosen as the database, Shipyard creates one project in the organisation you named, in eu-central-1 unless you set another region, waits up to ten minutes for the database to report healthy, reads the pooled connection string and writes it to your host as DATABASE_URL. If you also chose Supabase Auth it reads the publishable and secret keys, creating them when the project has none, writes the three variables in the table below, and sets Site URL and the redirect allow list to your live domain. It finds an existing project by name before creating one, so running it twice does not use up your second free slot, and it does not touch your other projects.

It does not write RLS policies, since those depend on your data model, and it cannot create the account or the organisation. If the free plan's project limit is reached it stops and says so.

VariableValueSide
DATABASE_URLThe pooled connection string with the password filled inServer
NEXT_PUBLIC_SUPABASE_URLhttps://<ref>.supabase.coBrowser and server
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYThe publishable keyBrowser and server
SUPABASE_SECRET_KEYThe secret keyServer only

What the free plan does to a quiet project

As of November 2026 the free plan allows two active projects and pauses a project after a week of low activity. Supabase emails a warning first. A paused project keeps its data and settings and comes back when you press Resume project in the dashboard, but until then your app gets connection errors. For anything with customers, the paid plan removes pausing; for a side project, a few database requests a day are normally enough to stay awake.

The two-project limit shows up at a bad moment: creating a third project fails. Pause or delete one you no longer use before starting the next product.

Sources

Launch in an hour, not a weekend

Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.

See how it works

Read next