Permit data served through an org-scoped server route

The browser never touches the permit tables directly; every read and write goes through POST /api/permits with org_id and the user stamped server-side.

What it is

A single server route with four actions — answer, record, auto, latest. Reference tables (jurisdictions / permit_rules / permit_sources) are global and readable by any approved user; lead_permit_lookups is tenant data, always filtered by the caller's org. Writes are restricted to admin, sales, project_manager and crew_lead.

Also called: permit api security · tenant isolation · who can write a permit lookup

See it
Permit data served through an org-scoped server route
CustomerBuildingAmountStatus
Sutter KlineHobby Shop$12,220Draft
Delia YoderBarndominium$3,480Paid
Gideon AltHobby Shop$6,330Paid
Marlin Hoover40×64 Shop$12,220Draft
Sutter Kline40×64 Shop$6,520Open
Not a visual feature — if illustrated, a simple diagram: browser → /api/permits (org stamped) → Supabase. src/app/api/permits/route.ts. Sample data — no customer information appears here.
How it works
  1. 1Clerk auth plus an approved account status is required for any action
  2. 2org_id and looked_up_by are stamped from the session — 'client values are ignored, so a tenant can't write into another org's namespace'
  3. 3The 'latest' read filters by org_id and the supplied opportunity ids (capped at 500)
  4. 4Citation URLs for all returned jurisdictions are fetched in one query, replacing an N+1 the old client implementation did
Why we built it

The route's own header: 'The permit reference tables… and the tenant table (lead_permit_lookups) are NOT exposed through /api/db, and the browser has no Supabase client (the secret key is server-only).' It mirrors the /api/db auth model rather than inventing a second one.

The problem
  • A browser-side database client leaks the key and the tenancy boundary
  • Per-jurisdiction citation queries hammer the database
Sound familiar?
What you get
One tenant's lookups are unreachable from another's session
One batched query instead of N

See it on your own jobs

Twenty minutes, your numbers, no slide deck. We’ll build one of your real buildings in front of you and send you the estimate link at the end — yours to keep either way.

or keep browsing features →