Build a Crowdsourced Rent Map
Build an anonymous rent map with Supabase security and a live Netlify link.
Introduction
30 Second Summary
In Bangalore, a broker might quote ₹40K for a 2BHK while a neighbour pays ₹28K. Harshit Anand's weekend-built anonymous map drew 2,200+ people who pinned ₹120 Cr+ of rent in 5 days with zero ads.
In this project, you will use Claude Code to build a public rent map for your city with Leaflet 1.9.4 over a Supabase database. You will protect its anonymous pins at the database layer before sharing the finished site through Netlify Drop.
What You'll Build
From a phone, you will add an anonymous rent pin to a public city map whose labelled marker remains visible after your computer reloads.
By the end of this project, you'll have:
- A public rent map where anyone can tap a location to save a rounded anonymous pin without signing up. The same labelled marker remains after a reload beneath visible OpenStreetMap credit.
- Database-enforced submission protections that reject a rent of 0. The fourth pin in one hour shows Too many pins, try again later.
- An intentional Row Level Security failure showing that the first insert has no policy. A browser delete attempt later prints exactly 0 rows deleted while every pin remains.
- Secret Mission: Add a privacy-aware local median for pins within 1 km. Any result based on fewer than 3 matching pins stays hidden.
Are there any prerequisites?
You need a Claude Pro, Max, Ultra, Team, Enterprise, or Console account.
You need a Mac running macOS 13.0 or later, or a PC running Windows 10 version 1809 or later or Windows 11.
No database or web development knowledge is required.
Before We Start
Before any hands-on work, this is your moment to commit to the city your rent map will cover. Naming who would benefit from clearer local rent data gives the project a real problem to solve.
Install Claude Code and Draw Your City
Claude Code gives you a working city map before the database has anything useful to support.
The generated index.html uses Leaflet version 1.9.4 with OpenStreetMap standard tiles. You finish with a full-screen map centered on the city you chose.
In this step, get ready to:
- Set up Claude Code.
- Start Claude Code in the rent-map folder.
- Generate the city map.
Install and verify Claude Code
Claude Code runs from a terminal session. Its native installer provides separate commands for macOS and Windows.
macOS
- Start Terminal.
- Press Cmd+Space to open Spotlight.
- Type Terminal.
- Press Enter.
- Install Claude Code by running this command:
curl -fsSL https://claude.ai/install.sh | bash
What does this command do?
This command downloads the official Claude Code installer. Your shell passes the installer to bash so it can install Claude Code.
- Close the current Terminal window after the installation finishes.
- Start a fresh Terminal window.
- Press Cmd+Space to open Spotlight.
- Type Terminal.
- Press Enter.
- Verify the installation by running this command:
claude --version
What does this command do?
The --version flag asks Claude Code to print its installed version. A version number proves the fresh Terminal session can find the command.
You should see a version number in Terminal.
Windows
- Start PowerShell.
- Press the Windows key to open search.
- Type PowerShell.
- Press Enter.
- Install Claude Code by running this command:
irm https://claude.ai/install.ps1 | iex
What does this command do?
This command downloads the official Claude Code installer. PowerShell executes the downloaded installer to add Claude Code to your PC.
- Close the current PowerShell window after the installation finishes.
- Start a fresh PowerShell window.
- Press the Windows key to open search.
- Type PowerShell.
- Press Enter.
- Verify the installation by running this command:
claude --version
What does this command do?
The --version flag asks Claude Code to print its installed version. A version number proves the fresh PowerShell session can find the command.
You should see a version number in PowerShell.
✔️ I see a version number
Claude Code is installed and available in your fresh terminal session.
ⓧ I don't see a version number
The installer may not have finished correctly. A fresh terminal session also needs to be started before it can find the new command.
- Return to the official Claude Code setup guide.
- Repeat the installer for your operating system.
- Close the terminal after the installer finishes.
- Start a fresh terminal session.
- Check the installation again by running:
claude --version
What does this command do?
This command prints the installed Claude Code version. Seeing a version number confirms the reinstall worked.
Start Claude Code in the rent-map folder
The folder where you launch Claude Code becomes the project it can work on. Keeping rent-map on your Desktop makes the files easy to find later.
macOS
- Move to your Desktop by running this command:
cd ~/Desktop
What does this command do?
The cd command changes Terminal's current folder. The ~ symbol represents your home folder.
Windows
- Move to your Desktop by running this command:
Set-Location $HOME\Desktop
What does this command do?
The Set-Location command changes PowerShell's current folder. The $HOME value points to your Windows home folder.
- Create the rent-map folder by running this command:
mkdir rent-map
What does this command do?
The mkdir command creates a folder. The new folder is named rent-map.
Your terminal should return to its prompt without an error, which confirms the folder was created.
- Move into the rent-map folder by running this command:
cd rent-map
What does this command do?
This command changes the terminal's current folder to rent-map. Files created during the Claude Code session now stay together in that folder.
The next command starts an interactive Claude Code session. It sends you through a browser login because this is the first session on your computer.
- Start Claude Code inside the rent-map folder by running this command:
claude
What does this command do?
The claude command opens an interactive Claude Code session in the current folder. Claude Code can now create and edit files inside rent-map.
- Sign in to Claude Code with your eligible Claude account.
- Follow the browser login prompt from Claude Code.
- Return to the terminal after the login finishes.
That's the setup hurdle cleared. You should see an active Claude Code session running inside the rent-map folder.
Ask Claude Code to draw the map
Your prompt fixes the map library version and the tile source. It also keeps the required OpenStreetMap attribution visible.
- Send this message to Claude Code with <my city> replaced by your chosen city:
Create index.html: a full-screen Leaflet 1.9.4 map (from unpkg) centred on <my city>, using OpenStreetMap tiles with the "© OpenStreetMap contributors" credit visible. Then open it in my browser.
What will Claude Code do?
Claude Code creates index.html inside the rent-map folder. The file loads Leaflet version 1.9.4 with OpenStreetMap standard tiles.
Claude Code then asks for permission to open the file in your browser. You approve only the command that matches your operating system.
- Approve Claude Code's request to create index.html.
- Use the approval option shown beside the file-write request in Claude Code.
Before you approve the browser command, do you expect the page to show a usable city map or an empty screen?
macOS
- Approve only this browser-opening command when Claude Code shows it:
open index.html
What does this command do?
The open command sends index.html to the browser registered for local web pages on your Mac.
Windows
- Approve only this browser-opening command when Claude Code shows it:
start index.html
What does this command do?
The start command sends index.html to the browser registered for local web pages on your Windows PC.
You should see a full-screen map centered on your chosen city.
Map missing or blank?
- Confirm Claude Code created index.html inside the rent-map folder.
- Confirm you approved the browser-opening command for your operating system.
- Still stuck? Help me troubleshoot my blank Leaflet map.
✔️ Awesome, I've got everything!
Your index.html file is saved inside rent-map. Keep the map page available for the final check.
ⓧ I'd like to double check the full code
Claude Code may vary the city center while keeping this map structure. Compare your index.html with this reference file:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rent Map</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
<style>
html, body, #map { height: 100%; margin: 0; }
</style>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
</head>
<body>
<div id="map"></div>
<script>
const CITY_CENTER = [0, 0];
const map = L.map('map').setView(CITY_CENTER, 12);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap contributors'
}).addTo(map);
</script>
</body>
</html>
- Zoom the map once to confirm it responds to your input.
You should see the map zoom while © OpenStreetMap contributors remains visible at the bottom-right.
Your city now has an interactive map with visible attribution. Next up, you create the minimal database table that preserves anonymous rent pins.
Create the Pins Table in Supabase
Your Leaflet map now gives your city an interactive canvas. The next job is to make future pins survive after someone closes the browser tab.
A deliberately minimal Supabase table preserves pins beyond the browser tab without collecting personal data.
In this step, get ready to:
- Create the Supabase rent-map project on the Free plan.
- Generate schema.sql with Claude Code.
- Run schema.sql in the Supabase SQL Editor.
Create the Supabase rent-map project
The Free plan is enough for this project. Your public table will contain six fixed fields with no names, emails, notes, exact addresses, or raw IPs.
- Create a free account on Supabase.
- Use the account creation control on the Supabase home page.
- Complete the on-screen sign-up flow until Supabase shows your dashboard.
You should see the Supabase dashboard for your new account.
- Create the Supabase rent-map project with rent-map as its name on the Free plan.
- Use the dashboard control for creating a project.
- Enter rent-map as the project name.
- Choose Free as the plan.
- Follow the remaining project setup prompts for your account.
- Confirm the project creation when every required field is complete.
You should see the dashboard for the Supabase rent-map project. Good progress. The hosted database is ready for its first table.
Ask Claude Code for the table SQL
The schema must capture only the values the rent map needs. It also sets the data limits before a pin can enter the database.
- In the Claude Code session from earlier, generate schema.sql by sending this exact message:
Write schema.sql for Supabase: a pins table with id, lat and lng as numeric(8,3), rent as a whole number that must be above 0 and below 10,000,000, bedrooms from 0 to 6, and created_at defaulting to now. No other columns. Enable row level security, revoke all from anon and authenticated, then grant only select and insert to anon. Do not add any policies yet.
What does this prompt ask for?
The six fixed columns hold an ID, rounded coordinates, rent, bedrooms, and a creation time. The rent checks accept whole numbers above 0 and below 10,000,000.
The Row Level Security setup leaves the table without policies. The anon role receives only select and insert grants.
- Approve the request to write schema.sql.
- Select the option that allows Claude Code to write the file.
Claude Code creates schema.sql inside the existing rent-map folder.
- Decline any request to install the Supabase CLI.
- Decline any request to connect an MCP server.
- Decline any request to run the SQL automatically.
- Choose the option that denies a Supabase CLI installation request.
- Choose the option that denies an MCP server connection request.
- Choose the option that denies an automatic SQL execution request.
The only approved change should be the new schema.sql file.
✔️ Awesome, I've got everything!
Your schema.sql file is ready for the Supabase SQL Editor.
ⓧ I'd like to double check the full code
- Compare the complete contents of schema.sql with this reference:
create table public.pins (
id uuid primary key default gen_random_uuid(),
lat numeric(8,3) not null,
lng numeric(8,3) not null,
rent integer not null check (rent > 0 and rent < 10000000),
bedrooms smallint not null check (bedrooms between 0 and 6),
created_at timestamptz not null default now()
);
alter table public.pins enable row level security;
revoke all on table public.pins from anon, authenticated;
grant select, insert on table public.pins to anon;
This file creates the six-column pins table. It enables Row Level Security before assigning the two required privileges.
- Use the reference as the full replacement contents if your schema.sql file differs.
Run schema.sql yourself
Table grants and RLS enforce separate layers of access. This least privilege setup permits the required operations at table level while the missing policies keep API row access locked.
- Copy the complete contents of schema.sql from the file Claude Code created.
- Paste the contents of schema.sql into a new query in the Supabase SQL Editor.
- Return to the Supabase rent-map project from earlier.
- Select SQL Editor.
- Start New Query.
- Click inside the empty query editor.
- Paste the complete contents of schema.sql.
Before you run the query, do you expect Supabase to create the table successfully with no data rows to return?
- Run schema.sql in the Supabase SQL Editor.
- Click Run in the SQL Editor.
You should see Success. No rows returned. That confirms Supabase accepted the complete schema.
Query did not succeed?
- Confirm that you pasted the complete contents of schema.sql into an empty query.
- Compare every table name, column name, constraint, and privilege with the full-code reference.
- Still stuck? Help me diagnose my schema query.
- Inspect the pins table in the Supabase Table Editor.
- Select Table Editor in the Supabase project.
- Select the pins table.
You should see exactly id, lat, lng, rent, bedrooms, and created_at. No personal-data columns appear.
The database now has RLS enabled. The anon role has only select and insert grants with no RLS policies yet.
Your Supabase rent-map project now has a minimal table for anonymous rent pins. Next, you'll connect the map to this locked database.
Connect the Map and Watch the Lock Hold
Your Supabase rent-map project now has the six fields needed for anonymous rent pins. The next goal is to connect that database to the map you already built.
Seeing Row Level Security block the first insert before any policy exists proves the database lock is holding.
A commenter pointed out his database was left open. Your map deliberately begins in the opposite state.
In this step, get ready to:
- Connect index.html to the Supabase rent-map project.
- Witness the database block the first anonymous insert.
- Save a rent pin that remains visible after a reload.
Connect the map with the publishable key
A browser-safe publishable key lets Claude Code connect your page to the Data API. The database still applies its grants and row security to every request made with that key.
- Copy the Project URL from the Connect dialog in the Supabase rent-map project.
- Return to the Supabase rent-map project from earlier.
- Click Connect at the top of the project dashboard.
- Use the copy control beside the Project URL.
- Copy the publishable key beginning with sb_publishable_... from the Connect dialog.
- Return to the Connect dialog from the previous action.
- Use the copy control beside the publishable key.
- Switch back to the Claude Code session in the rent-map folder. Replace <url> and <key> in this exact message before sending it:
Add supabase-js 2 from jsdelivr to index.html with my project URL <url> and publishable key <key>. Load every pin and show it as a marker labelled like "₹28,000 · 2 bed" in my currency. When I tap the map, show a small form for rent and bedrooms, round the location to 3 decimal places, and save it. Show any error on the page.
What does this prompt do?
- The prompt adds the browser client for supabase-js major version 2.
- It gives index.html the Project URL and publishable key needed to reach the pins table.
- It asks the page to round each latitude and longitude to 3 decimal places before saving.
- It keeps database errors visible on the page so the next security check has an observable result.
- Approve the requested write to index.html.
Claude Code updates index.html with the connection values, marker loading, rounded pin saving, and an on-page status message.
- Confirm the key assigned to PUBLISHABLE_KEY begins with sb_publishable_....
Keep the secret key out of the page
A key beginning with sb_secret_... bypasses RLS and must never appear in index.html. Browser code uses the publishable key beginning with sb_publishable_....
macOS
- Approve only this browser-opening command if Claude Code asks to reopen index.html:
open index.html
What does this command do?
The open command sends index.html to its registered browser application on macOS.
Your browser reloads the local rent map with its new database connection.
Windows
- Approve only this browser-opening command if Claude Code asks to reopen index.html:
start index.html
What does this command do?
The start command opens index.html through its registered browser application on Windows.
Your browser reloads the local rent map with its new database connection.
- Tap a location on the rent map.
- Return to the rent map browser tab opened by Claude Code.
- Click any location inside the mapped city.
You should see a small form with Monthly rent and Bedrooms fields. The © OpenStreetMap contributors credit remains visible at the bottom-right.
✔️ Awesome, I've got everything!
Your connected rent form is ready. Keep index.html saved with your real Project URL and publishable key.
ⓧ I'd like to double check the full code
- Compare your index.html structure with this reference.
- Keep your actual PROJECT_URL, PUBLISHABLE_KEY, and CITY_CENTER values in your file.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rent Map</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
<style>
html, body, #map { height: 100%; margin: 0; }
body { font-family: system-ui, sans-serif; }
#status {
position: fixed;
top: 12px;
left: 50%;
transform: translateX(-50%);
z-index: 1000;
max-width: min(90vw, 520px);
padding: 10px 14px;
border-radius: 8px;
background: white;
box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
#status:empty { display: none; }
.pin-form { display: grid; gap: 8px; min-width: 210px; }
.pin-form label { display: grid; gap: 4px; }
.pin-form input, .pin-form select, .pin-form button { font: inherit; }
</style>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
</head>
<body>
<div id="status" role="status" aria-live="polite"></div>
<div id="map"></div>
<script>
const PROJECT_URL = 'your-supabase-project-url-here';
const PUBLISHABLE_KEY = 'sb_publishable_your-key-here';
const CITY_CENTER = [0, 0];
const CURRENCY = '₹';
window.rentMapDb = supabase.createClient(PROJECT_URL, PUBLISHABLE_KEY);
const map = L.map('map').setView(CITY_CENTER, 12);
const statusBox = document.querySelector('#status');
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap contributors'
}).addTo(map);
function setStatus(message) {
statusBox.textContent = message || '';
}
function pinLabel(pin) {
return `${CURRENCY}${Number(pin.rent).toLocaleString()} · ${pin.bedrooms} bed`;
}
function addMarker(pin) {
L.marker([Number(pin.lat), Number(pin.lng)])
.addTo(map)
.bindTooltip(pinLabel(pin));
}
async function loadPins() {
const { data, error } = await rentMapDb
.from('pins')
.select('id,lat,lng,rent,bedrooms,created_at');
if (error) {
setStatus(error.message);
return;
}
data.forEach(addMarker);
}
map.on('click', (event) => {
const form = document.createElement('form');
form.className = 'pin-form';
form.innerHTML = `
<label>Monthly rent
<input name="rent" type="number" min="1" max="9999999" step="1" required>
</label>
<label>Bedrooms
<select name="bedrooms" required>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</label>
<button type="submit">Add anonymous pin</button>
`;
form.addEventListener('submit', async (submitEvent) => {
submitEvent.preventDefault();
setStatus('Saving pin...');
const values = new FormData(form);
const pin = {
lat: Number(event.latlng.lat.toFixed(3)),
lng: Number(event.latlng.lng.toFixed(3)),
rent: Number(values.get('rent')),
bedrooms: Number(values.get('bedrooms'))
};
const { data, error } = await rentMapDb
.from('pins')
.insert(pin)
.select('id,lat,lng,rent,bedrooms,created_at');
if (error) {
setStatus(error.message);
return;
}
addMarker(data[0]);
map.closePopup();
setStatus('Pin saved');
});
L.popup().setLatLng(event.latlng).setContent(form).openOn(map);
});
loadPins();
</script>
</body>
</html>
Trigger the intentional RLS failure
The anon grant allows the request to reach the table operation. The active row lock still decides whether that request may create a row.
- Enter 28000 in the Monthly rent field.
- Click the Monthly rent field in the open map form.
- Type 28000.
- Select 2 in the Bedrooms field.
- Click the Bedrooms menu in the open form.
- Choose 2.
Before you submit the pin, do you think the table grant is enough to let the new row through?
- Submit the pin by clicking Add anonymous pin.
- Click Add anonymous pin at the bottom of the open form.
The page should show new row violates row-level security policy for table "pins" instead of adding a marker.
🚨 This failure is intentional
The database received a valid insert request through the anon grant. RLS refused the new row because no insert policy allows it through.
You have now seen the lock hold before changing it. That failure is the security proof this step was designed to expose.
Add only the required policies
A select policy lets anonymous visitors read pins through Postgres. An insert policy checks whether a new pin may become a row.
- Switch back to Claude Code. Send this message word for word:
Write policies.sql: one policy letting anon select all pins, and one letting anon insert pins. Explain each in one sentence.
What does this prompt do?
The prompt asks for one SELECT policy using using (true). This permits the map to load every anonymous pin.
It also asks for one INSERT policy using with check (true). This lets a new anonymous pin pass the row check.
- Approve the requested write to policies.sql.
Claude Code creates policies.sql with one read policy and one insert policy.
Claude Code also explains the purpose of each policy in one sentence.
✔️ Awesome, I've got everything!
The policy file is ready. Save policies.sql before running it in Supabase.
ⓧ I'd like to double check the full code
Compare the complete policies.sql file with this reference.
create policy "anon can read pins"
on public.pins
for select
to anon
using (true);
create policy "anon can insert pins"
on public.pins
for insert
to anon
with check (true);
- Copy every line from policies.sql.
- Paste the copied SQL into a new query in the Supabase SQL Editor.
- Return to the Supabase SQL Editor from earlier.
- Click New Query.
- Paste the copied contents of policies.sql into the query editor.
- Run the policy query by clicking Run.
- Click Run above the query editor.
You should see Success. No rows returned. The anon can read pins and anon can insert pins policies are now active.
- Submit the same ₹28,000 two-bedroom pin again by clicking Add anonymous pin.
- Switch back to the rent map browser tab from earlier.
- Click Add anonymous pin in the still-open form.
You should see Pin saved at the top of the page. A marker labelled ₹28,000 · 2 bed appears on the map.
Before you reload the page, do you expect the new marker to remain or disappear?
- Reload index.html in the browser.
- Use the reload control in the rent map browser tab.
The ₹28,000 · 2 bed marker should return after the reload. The © OpenStreetMap contributors credit remains visible at the bottom-right.
Pin still blocked after running the policies?
- Confirm the Supabase SQL Editor showed Success. No rows returned after you ran policies.sql.
- Check that the file creates the policy named anon can insert pins on public.pins for the anon role.
- Still stuck? Help me diagnose why my Supabase insert remains blocked after adding the anon insert policy.
That lock now opens only for the two actions your rent map needs. Next, you'll make the database reject spam, invalid rent, and browser delete attempts.
Stop Spam and Prove It Is Anonymous
Your rent map now saves rounded anonymous pins that remain after a reload. The next goal is protecting that public insert path while keeping existing pins readable.
Public anonymous inserts can be flooded with junk, so the Supabase database must enforce the fixed three-pins-per-hour limit.
In this step, get ready to:
- Add the private rate limit.
- Trigger the hourly limit and rent constraint.
- Attempt a browser deletion.
Add the private rate limit
The fixed limit runs through a database trigger before each insert. Its private records use salted hashing without storing raw IPs.
- Send this exact request in the Claude Code session from earlier:
Write limits.sql: a before-insert trigger on pins that allows at most 3 pins per hour per visitor. Identify the visitor by the first IP in the x-forwarded-for request header, but store only a salted sha256 hash of it, with a timestamp, in a table in a private schema the API can't reach, and delete hashes older than a day. Refuse with the message "Too many pins, try again later".
What does this prompt do?
- The private.pin_rate_limit_config table holds the salt used for each visitor hash.
- The private.pin_rate_limits table holds only visitor_hash and created_at records.
- The private.check_pin_rate_limit() function removes records older than one day. It refuses an insert once the same visitor has saved three pins within one hour.
- The enforce_pin_rate_limit trigger runs the function before each insert into pins.
Claude Code creates limits.sql inside the existing rent-map folder. It asks for permission before writing the file.
- Approve the file write for limits.sql.
You should now have limits.sql beside index.html, schema.sql and policies.sql.
- Copy every line from limits.sql.
- Paste the copied contents of limits.sql into a new query in the Supabase SQL Editor.
- Return to the Supabase rent-map project's SQL Editor from earlier.
- Select New Query.
- Paste the copied SQL into the query editor.
- Execute the complete limits.sql query.
- Click Run.
You should see the query finish successfully. The public pins table still contains only id, lat, lng, rent, bedrooms and created_at.
✔️ Awesome, I've got everything!
Your private rate-limit tables and before-insert trigger are ready for live requests from the rent map.
ⓧ I'd like to double check the full code
Compare your complete limits.sql file with this reference:
create schema if not exists private;
revoke all on schema private from public, anon, authenticated;
create extension if not exists pgcrypto with schema extensions;
create table if not exists private.pin_rate_limit_config (
singleton boolean primary key default true check (singleton),
salt text not null
);
insert into private.pin_rate_limit_config (singleton, salt)
values (true, gen_random_uuid()::text || gen_random_uuid()::text)
on conflict (singleton) do nothing;
create table if not exists private.pin_rate_limits (
visitor_hash text not null,
created_at timestamptz not null default now()
);
revoke all on table private.pin_rate_limit_config from public, anon, authenticated;
revoke all on table private.pin_rate_limits from public, anon, authenticated;
create index if not exists pin_rate_limits_lookup_idx
on private.pin_rate_limits (visitor_hash, created_at desc);
create or replace function private.check_pin_rate_limit()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
declare
request_headers text;
visitor_ip text;
project_salt text;
hashed_visitor text;
recent_count integer;
begin
request_headers := current_setting('request.headers', true);
if request_headers is null or request_headers = '' then
raise exception 'Missing x-forwarded-for request header';
end if;
visitor_ip := split_part(request_headers::json ->> 'x-forwarded-for', ',', 1);
visitor_ip := btrim(visitor_ip);
if visitor_ip is null or visitor_ip = '' then
raise exception 'Missing x-forwarded-for request header';
end if;
select salt
into project_salt
from private.pin_rate_limit_config
where singleton = true;
hashed_visitor := encode(
extensions.digest((project_salt || ':' || visitor_ip)::bytea, 'sha256'),
'hex'
);
delete from private.pin_rate_limits
where created_at < now() - interval '1 day';
select count(*)
into recent_count
from private.pin_rate_limits
where visitor_hash = hashed_visitor
and created_at >= now() - interval '1 hour';
if recent_count >= 3 then
raise exception 'Too many pins, try again later';
end if;
insert into private.pin_rate_limits (visitor_hash)
values (hashed_visitor);
return new;
end;
$$;
revoke all on function private.check_pin_rate_limit() from public, anon, authenticated;
drop trigger if exists enforce_pin_rate_limit on public.pins;
create trigger enforce_pin_rate_limit
before insert on public.pins
for each row execute function private.check_pin_rate_limit();
Force both database checks to fire
The rent constraint and hourly limit protect different parts of each insert. Test the rent constraint first so the three successful submissions remain available for the hourly-limit check.
- Temporarily change the live monthly rent input's min value from 1 to 0 in your browser developer tools.
- Return to the rent map from earlier.
- Tap a location to display the pin form.
- Use the element inspector to select the monthly rent input.
- Edit the displayed min attribute from 1 to 0.
The live form should now accept 0 as an input, which lets the request reach the database constraint.
- Submit the pin with rent 0 and bedrooms 2.
- Enter 0 in the monthly rent field.
- Select 2 in the bedrooms field.
- Click Add anonymous pin.
You should see a database error on the page. No marker is added because the pins table rejects a rent of 0.
Missing the request header?
If the page reports Missing x-forwarded-for request header, the trigger could not read that header in your environment. Use Supabase's documented pre-request pattern for the same check.
- Send this fallback request to Claude Code:
Update limits.sql so the same 3-pins-per-hour salted sha256 check runs from a Supabase pre-request function because x-forwarded-for is empty in the trigger. Keep private.pin_rate_limits, one-day cleanup, and the exact message "Too many pins, try again later". Replace the trigger approach, then tell me which SQL to rerun.
Claude Code rewrites limits.sql so the Data API runs the same check through a pre-request function. It also tells you which updated SQL to execute.
- Approve the updated limits.sql file write.
- Replace the current SQL Editor query with the updated contents of limits.sql.
- Click Run.
- Retry the zero-rent submission.
Still stuck? Help me troubleshoot the Supabase request-header fallback.
- Submit one valid pin with rent 28000 and bedrooms 2.
- Tap a new location on the rent map.
- Enter 28000 in the monthly rent field.
- Select 2 in the bedrooms field.
- Click Add anonymous pin.
You should see Pin saved with a new labelled marker on the map.
- Repeat the same submission at two other map locations with rent 28000 and bedrooms 2.
- Tap a second location on the map.
- Enter 28000 in the monthly rent field.
- Select 2 in the bedrooms field.
- Click Add anonymous pin.
- Repeat these steps at a third location.
You should see three new labelled markers. Each successful insert occupies one place in the hourly limit.
Before you submit another pin, do you expect the fourth attempt to create a marker or show the fixed refusal message?
- Submit a fourth pin with rent 28000 and bedrooms 2.
- Tap another location on the rent map.
- Enter 28000 in the monthly rent field.
- Select 2 in the bedrooms field.
- Click Add anonymous pin.
You should see exactly Too many pins, try again later. The fourth marker is absent.
Attempt a delete from the browser
Your Row Level Security policies allow anonymous clients to select and insert pins. No delete policy exists, so the publishable browser client should delete zero rows.
- Send this exact request to Claude Code:
Give me one line to paste in the browser console that tries to delete every pin with the publishable key and prints how many rows were deleted.
What does this prompt do?
Claude Code uses the existing window.rentMapDb client to request a delete through the publishable key. The returned rows reveal how many pins the browser was allowed to remove.
- Decline any request from Claude Code to run a shell command.
Claude Code replies with one browser-console line. It does not need to edit a file.
- Return to the rent map with the fixed refusal message still visible.
- Open your browser's developer tools.
- Select the console panel.
Before you run the line, do you expect the publishable client to remove the pins or report a zero count?
- Attempt to delete every pin by running this line in the browser developer console:
rentMapDb.from('pins').delete().neq('id','00000000-0000-0000-0000-000000000000').select().then(({data}) => console.log(`${data?.length ?? 0} rows deleted`))
What does this code do?
- The delete() call requests deletion through the same browser client used by the rent map.
- The neq() filter targets every real pin ID.
- The select() call returns any rows the request deleted. The final expression prints their count.
You should see exactly 0 rows deleted in the console. The labelled markers remain on the map.
- Reload the rent map.
You'll see the existing markers return with the OpenStreetMap credit still visible. That's the proof complete: anonymous visitors can contribute pins while delete access stays closed.
Your rent map now rejects excessive inserts, refuses invalid rent and preserves every pin during a browser delete attempt. Next, you'll deploy these protections behind a public link.
Put It Live for Free
Your Supabase database now rejects excessive inserts while keeping delete access locked down. Your next goal is to give that protected map a public address with Netlify Drop.
A local map cannot spread by word of mouth. This step publishes the protected rent-map folder at a public netlify.app URL that works on a phone.
In this step, get ready to:
- Deploy the rent-map folder with Netlify Drop.
- Claim the Netlify rent-map site.
- Test the public link across two devices.
Deploy the rent-map folder
Netlify Drop publishes the files that already make your rent map work. Uploading the entire folder keeps index.html, schema.sql, policies.sql, and limits.sql together.
- Go straight to Netlify Drop.
- Deploy the entire rent-map folder to the drop area.
- Use your computer's file manager to locate the local rent-map folder from earlier.
- Drag the rent-map folder into the drop area on the Netlify Drop page.
You should see a preview URL ending in netlify.app after the folder finishes uploading.
- Load the generated preview URL shown by Netlify.
- Select the generated netlify.app address on the deployment result.
Your first public preview is live when you see the zoomable rent map with © OpenStreetMap contributors visible at the bottom-right.
Turn the preview into the Netlify rent-map site
An unclaimed preview is separate from your account. Claiming it gives you a Netlify rent-map site that you can manage.
- Claim the preview deployment with a free Netlify account.
- Use the claim option shown with the preview deployment.
- Complete the account sign-up flow that Netlify opens.
You should see the claimed deployment appear in your Netlify account as the Netlify rent-map site.
- Set the Netlify rent-map site's visibility to public.
- Locate the visibility control on the claimed project page.
- Choose the public visibility option.
The site is ready to share when its public netlify.app URL can load without Netlify account access.
- Rename the Netlify rent-map site using your chosen city in lowercase followed by -rent.
- Locate the project name control on the claimed project page.
- Apply the new site name based on your chosen city.
That hosting milestone is complete when the renamed site has a public URL ending in netlify.app.
- Record your final public URL here: https://your-city-rent.netlify.app.
Test the public link across two devices
A public link is useful when both devices reach the same Supabase data. The visible OpenStreetMap credit must survive the deployment.
- Load https://your-city-rent.netlify.app in the browser already running on your computer.
- Enter your final Netlify URL in the computer browser's address bar.
You should see the same rent map with its existing pins and visible © OpenStreetMap contributors credit.
- Load https://your-city-rent.netlify.app on your phone.
- Enter the same final Netlify URL in your phone's address bar.
The rent map should load on your phone without asking for Netlify account access.
- Start a new phone pin at any location on the public map.
- Tap a location once to open the pin form.
You should see the rent and bedroom fields for the selected location.
- Set the pin's monthly rent to 28000.
- Enter 28000 in the Monthly rent field.
- Set the pin's bedroom count to 2.
- Choose 2 in the Bedrooms list.
- Save the phone pin.
- Tap Add anonymous pin in the pin form.
You should see a labelled marker for rent 28000 with 2 bedrooms on the phone map.
Phone pin refused by the rate limit?
If the page shows Too many pins, try again later, that visitor identity has already submitted 3 pins within the current hour. Wait until the one-hour window has passed before saving the phone pin again.
Still stuck? Help me complete the cross-device test without weakening the rate limit.
Before you reload the computer, do you expect the phone pin to already be in the shared database?
- Reload the public rent map on your computer.
- Use the browser's reload control on the computer page showing the public Netlify rent map.
You have the full cross-device loop working when the phone pin appears on the computer after the reload. You should still see © OpenStreetMap contributors at the bottom-right.
Secret mission
Reveal the Local Two-Bed Median
Turn nearby anonymous pins into a local rent signal. A tap and hold shows median rent by bedroom count within 1 km while hiding groups with fewer than 3 pins.
Clean Up Your Resources
Clean Up Your Resources
Your Supabase rent-map project and Netlify rent-map site use Free plans. Choose whether to keep them active, let the database pause, or delete the hosted resources plus your local rent-map folder.
Resources you used:
- The local rent-map folder containing index.html, schema.sql, policies.sql, and limits.sql.
- The Supabase rent-map project containing the public pins table, its Row Level Security policies, and the three-per-hour limit backed by private.pin_rate_limits.
- The claimed Netlify rent-map site serving the public rent map from its netlify.app URL.
Keep everything running
No action is needed. Choose this if you want the public rent map to keep accepting pins and showing local medians.
- Keep the Supabase rent-map project active so the map can read pins and accept permitted inserts.
- Keep the Netlify rent-map site deployed at its current netlify.app URL.
- Retain the local rent-map folder so you can edit and redeploy the site later.
Pause - I'll come back to this later
Let the database pause while keeping the deployed site and local files available for later work.
- Leave the Supabase rent-map project unused for one week.
- Keep the Netlify rent-map site deployed at its current netlify.app URL.
- Retain the local rent-map folder with all four project files.
Supabase pauses Free projects after one week of inactivity. The static site remains deployed while the paused database stops serving its pin data.
Delete - I don't want to use this again
Removing the hosted resources permanently takes the public rent map offline. Your local files stay untouched until the final cleanup.
Delete the Netlify rent-map site:
- Select the Netlify rent-map site from your project list in Netlify.
- Find the permanent deletion control on the selected site's management page.
- Use the control that permanently deletes the Netlify rent-map site.
- Confirm the permanent deletion when Netlify asks.
- Return to your Netlify project list.
You should no longer see the Netlify rent-map site in the project list. Its former netlify.app URL no longer serves the rent map.
Delete the Supabase rent-map project:
- Select the Supabase rent-map project from your project list in Supabase.
- Find the permanent deletion control on the selected project's management page.
- Use the control that permanently deletes the Supabase rent-map project.
- Confirm the permanent deletion when Supabase asks.
- Return to your Supabase project list.
You should no longer see the Supabase rent-map project. Deleting it also removes the pins table, its policies, the rate-limit function, its trigger, and the private rate-limit records.
Delete the local project folder:
macOS
- Close any Terminal or editor window currently using the rent-map folder.
- Search for rent-map in Finder.
- Select the rent-map folder containing index.html, schema.sql, policies.sql, and limits.sql.
- Use Finder's folder deletion action to move the selected folder to the trash.
- Permanently remove only the rent-map folder from the trash.
- Search for rent-map in Finder again.
You should no longer find the local rent-map folder or its project files.
Windows
- Close any PowerShell or editor window currently using the rent-map folder.
- Search for rent-map in File Explorer.
- Select the rent-map folder containing index.html, schema.sql, policies.sql, and limits.sql.
- Use File Explorer's folder deletion action to move the selected folder to the recycle bin.
- Permanently remove only the rent-map folder from the recycle bin.
- Search for rent-map in File Explorer again.
You should no longer find the local rent-map folder or its project files.
Nice Work!
Nice Work!
Your crowdsourced rent map is now live at a public netlify.app link. It collects rounded anonymous rent pins behind database-enforced privacy controls.
You've learned how to:
- Create a full-screen Leaflet 1.9.4 rent map with Claude Code. Save rounded anonymous pins in Supabase.
- Experience an intentional Row Level Security failure before creating read and insert policies. Reject a rent of 0 through a database constraint. Enforce a limit of 3 pins per visitor per hour with salted visitor hashes. Prove delete access stays blocked when the console prints 0 rows deleted.
- Publish the rent-map folder as a public Netlify rent-map site. Verify a pin added on your phone appears on your computer. Keep OpenStreetMap attribution visible.
- Complete the optional Secret Mission by adding a privacy-aware local median for pins within 1 km. Hide rent values for groups with fewer than 3 pins.
Ready to quiz yourself?