Prompt: Set Up Local Supabase Dev Environment
Copy and paste this entire prompt to Claude Code when youβre ready to implement Option B.
Context
We have two Next.js apps that use Supabase for authentication and data:
-
accessible-org-chart β
~/Projects/accessible-org-chart/- Frontend: Next.js static export β Cloudflare Pages (
apps/web/) - API: Hono on Node.js in Docker (
workers/api/) - Auth: Supabase magic-link + Google OAuth
- Current dev workaround:
DevAutoLogincomponent readsNEXT_PUBLIC_DEV_AUTO_LOGIN_*from.env.localand callssupabase.auth.signInWithPasswordon mount (Option A, already implemented)
- Frontend: Next.js static export β Cloudflare Pages (
-
accessible-pdf-converter β
~/Projects/accessible-pdf-converter/- Frontend: Next.js static export β Cloudflare Pages (
apps/web/) - API: Hono Cloudflare Workers (
workers/api/) - Auth: Supabase magic-link + Google OAuth, multi-tenant
- Same
DevAutoLoginOption A already implemented
- Frontend: Next.js static export β Cloudflare Pages (
Both projects already have:
supabase/migrations/directories with the full schema historyapps/web/.env.local.exampledocumenting required env varsapps/web/.env.productionwith live Supabase credentials (DO NOT MODIFY)- Docker Compose for the org-chart API (
docker-compose.ymlat repo root)
Goal
Replace the Option A env-var auto-login with a fully isolated local Supabase stack so that:
- Local dev uses a completely separate database (no risk to production data)
- Schema migrations can be tested before deploying to production
- Test data can be seeded and reset freely
- The
DevAutoLogincomponent still works, just pointed at localhost Supabase
What to implement
1. Supabase CLI setup
- Verify
supabaseCLI is installed (supabase --version); install via Homebrew if not - Run
supabase initin each project root if asupabase/directory doesnβt already exist (it does β just verify) - The local Supabase stack requires Docker Desktop to be running
2. supabase/config.toml review
- Review and update
supabase/config.tomlin each project:project_idshould match the project name (e.g.accessible-org-chart)- Auth providers should match whatβs in production:
email(magic link + password),google - For local dev,
email.enable_confirmations = falseso we donβt need to click email links - Disable all external SMTP (use Supabaseβs built-in Inbucket for email capture)
3. Start the local stack
# In each project root:supabase startThis starts: Postgres (port 54322), Auth (port 54321), API (port 54321), Studio (port 54323), Inbucket email capture (port 54324).
After starting, supabase status outputs the local API URL, anon key, and service_role key.
4. .env.local updates
Update apps/web/.env.local in each project to point at local Supabase:
# Local Supabase (from `supabase status`)NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321NEXT_PUBLIC_SUPABASE_ANON_KEY=<local anon key from supabase status>
# Dev auto-login (unchanged β still used by DevAutoLogin component)NEXT_PUBLIC_DEV_AUTO_LOGIN_EMAIL=larry+dev@anglin.comNEXT_PUBLIC_DEV_AUTO_LOGIN_PASSWORD=<same password as before>For org-chart API (workers/api/.env), add:
SUPABASE_URL=http://localhost:54321SUPABASE_SERVICE_ROLE_KEY=<local service_role key from supabase status>SUPABASE_JWT_SECRET=<local JWT secret from supabase status>5. Run migrations locally
supabase db reset # applies all migrations in supabase/migrations/ from scratchVerify the schema matches production by inspecting Supabase Studio at http://localhost:54323.
6. Seed script
Create supabase/seed.sql for each project containing:
accessible-org-chart seed:
- A test user
larry+dev@anglin.comcreated viaauth.usersinsert (use Supabaseβscrypt()for password)- Alternatively, use
supabase authCLI:supabase auth admin create-user --email larry+dev@anglin.com --password <password>
- Alternatively, use
- 2β3 sample org charts owned by the test user
- Sample org chart people/relationships so the dashboard has data to display
- A test admin user
larry+admin@anglin.com
accessible-pdf-converter seed:
- A test user
larry+dev@anglin.comwith email/password auth - A default tenant record pointing to
localhost - 2β3 sample conversion jobs in various statuses (pending, completed, failed)
- A test admin user
The seed runs automatically on supabase db reset. Add a npm run db:reset script to each projectβs package.json:
"db:reset": "supabase db reset"7. Docker Compose integration (org-chart only)
The org-chart API runs in Docker. Update docker-compose.yml to add a dev profile that points the API at local Supabase instead of production. The production Docker Compose should remain unchanged.
Add a docker-compose.dev.yml override file:
# Usage: docker compose -f docker-compose.yml -f docker-compose.dev.yml up -dservices: api: environment: SUPABASE_URL: http://host.docker.internal:54321 SUPABASE_SERVICE_ROLE_KEY: <local service_role key> SUPABASE_JWT_SECRET: <local JWT secret>8. Update .env.local.example
Update apps/web/.env.local.example in each project to document the local Supabase values and how to get them via supabase status.
9. npm run dev convenience script (optional)
Consider adding a root-level dev script in each projectβs package.json that:
- Checks if Supabase is running (
supabase status) - Starts it if not (
supabase start) - Runs
next dev
10. Document in docs/admin/local-dev.md
Create a step-by-step runbook in each project at docs/admin/local-dev.md covering:
- Prerequisites (Docker Desktop, Supabase CLI, Node.js)
- First-time setup steps (clone β
.env.localβsupabase startβsupabase db resetβnpm run dev) - Day-to-day workflow
- How to reset to a clean state (
supabase db reset) - How to create and apply a new migration (
supabase migration new <name>β edit βsupabase db reset) - How to push a migration to production (
supabase db push)
Constraints
- Do NOT modify
apps/web/.env.productionin either project - Do NOT modify the production Docker Compose (
docker-compose.yml) in a way that breaks production deployment - The
DevAutoLogincomponent already exists β do NOT rewrite it, just ensure the local Supabase instance acceptssignInWithPasswordfor the dev user - All new files must follow existing code style (TypeScript strict, camelCase, etc.)
- The
supabase/migrations/directories must not be modified β run them as-is against local Supabase
Reference files to read first
Before starting, read these files in each project to understand the current state:
supabase/config.tomlβ Supabase project configurationsupabase/migrations/β all migration files (understand the schema)apps/web/.env.local.exampleβ env var documentationapps/web/src/lib/supabase.tsβ Supabase client setupworkers/api/.env.example(if it exists) β API env var documentationdocker-compose.yml(org-chart only) β current Docker setup