Files
orangecat/docs/operations/devops/supabase.md
CatoandClaude Opus 5.5 24c3d140ae docs: archive point-in-time records, fix live docs against the tree (#1349)
* docs: archive point-in-time records, drop broken guide symlinks

Status reports, progress trackers, audits, session summaries, completed
migration plans and the 2025 roadmap move to docs/archive/ (same relative
path), with a README saying they describe the day they were written.
.ai-guides/ held only symlinks into a docs/guides/ai/ that no longer
exists, tests/unit/docs/ held a stray copy of an old getting-started page,
and docs/operations/PORT_MANAGEMENT_README.md duplicated port-management.md;
all three are deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJkbo18cRNXtgPWZN2S9cD

* docs: correct drifted paths, links and versions in current docs

Fix in place the reference docs agents use: point paths at where the code
lives now (src/stores/auth.ts, src/lib/supabase/*, scripts/dev/*,
docs/reference/api/CONVENTIONS.md, the squashed baseline migration),
rewrite the development, features, operations and API index pages to list
documents that exist, say plainly where something is gone (/api/metrics,
the CSP report route, .envrc in the repo, Loki's `migrate` script), and
correct the Next.js major. docs-truth findings: 468 -> 2 (both "Next 30/90
Days" headings in the legal overview, a checker false positive).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJkbo18cRNXtgPWZN2S9cD

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-19 14:09:06 +02:00

2.4 KiB

Supabase Connectivity

Environment

  • Required (all environments):
    • NEXT_PUBLIC_SUPABASE_URL
    • NEXT_PUBLIC_SUPABASE_ANON_KEY
  • Optional (server-side admin only):
    • SUPABASE_SERVICE_ROLE_KEY (do not expose publicly)

Runtime Clients

  • Browser: src/lib/supabase/browser.ts (uses anon key, lazy validates env).
  • Server: src/lib/supabase/server.ts (SSR client using anon key + cookies for session handling).
  • Admin: src/lib/supabase/admin.ts (service-role client; falls back to a dummy that throws if missing to avoid unsafe usage).

Health Check

  • GET /api/health checks Supabase availability:
    • Tries admin client if SUPABASE_SERVICE_ROLE_KEY is present.
    • Falls back to SSR anon client if admin is absent.
    • Performs a minimal profiles query with head: true.

CLI-Free Local Diagnostics

  • Run node scripts/diagnostics/check-supabase.mjs to verify env + connectivity and head-only selects on key tables (profiles, organizations, funding_pages).
  • Uses .env.local (if present) and prefers SUPABASE_SERVICE_ROLE_KEY when available.

Write Test (optional)

  • Run node scripts/diagnostics/write-test-supabase.js to perform a safe end-to-end write test:
    • Creates a temporary auth user via Admin API (service-role required)
    • Ensures a profile exists (trigger or fallback insert)
    • Inserts a temporary funding_pages row (if owner column detected), then deletes it
    • Cleans up by deleting the temporary auth user (cascades to profile)
  • No existing data is modified; temporary records are removed at the end.

Local Development

  1. Use the remote self-hosted Supabase (supabase.orangecat.ch) — do not run a local stack.
  2. Set .env.local with the required keys (see .env.example).
  3. Run pnpm run dev (or pnpm run fresh:start).
  4. Verify via curl http://localhost:3000/api/health.

Production

  • Configure envs in /opt/orangecat/app/.env on the Hetzner box (Production):
    • NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY (required)
    • SUPABASE_SERVICE_ROLE_KEY (optional; only if admin operations are required at runtime)
  • Production points at the self-hosted Supabase at supabase.orangecat.ch.

Troubleshooting

  • Missing envs cause a runtime error on first Supabase client usage; /api/health will show supabase as down.
  • Verify the domain in NEXT_PUBLIC_SUPABASE_URL and that keys match the target environment (dev/staging/prod).