Connect a website form to Supabase safely
Create a free Supabase project, add a leads table, turn on Row Level Security and add one policy that lets the public anon role insert rows and nothing else. Paste the project URL and anon key into your page, test the form, and read submissions in the table editor. The anon key is meant to be public; the service_role key never goes in a page.
The steps
Create the project
Sign up for Supabase and create a free project with a name, a database password and a region close to your visitors. It takes about two minutes to be ready.
Create the leads table
In the SQL Editor create a table called leads with id, created_at, name, email, message, intent (subscribe, reach out or both), source and user_agent. Keep the fields to what you will actually use.
Turn on Row Level Security
Enable Row Level Security on the table. With RLS on, everything is denied unless a policy allows it.
Add one insert only policy
Add a single policy that lets the anon role insert rows. Do not add select, update or delete for anon. Visitors can now submit the form but cannot read, edit or delete anyone's data.
Copy the right keys
From Project Settings, API, copy the Project URL and the anon public key. Never use the service_role key in a web page: it bypasses every policy.
Paste them into the page
Put both values in the script block of your HTML file where the form sends its data. Until you do, a good setup falls back to opening the visitor's email app, so no lead is lost.
Test it
Submit the form yourself, check that the thank you message appears, then open Table Editor, leads, and confirm the row is there.
Get notified and reduce spam
For an email on every signup, add a database webhook that calls Resend, a Zapier webhook or an Edge Function. If spam appears, add a hidden honeypot field, Cloudflare Turnstile or hCaptcha, or a rate limit.
Common mistakes
- Leaving Row Level Security off
- Giving the anon role select access so the form can confirm duplicates
- Pasting the service_role key into the page
- Never testing the form after publishing
Where this comes from
This is the setup guide I gave attendees of my Claude 101 masterclass with GrowthX in June 2026, written for people who had never used a database. See more.