Skip to content

feat: Add LOCAL_ONLY mode for local development without Firebase/GCP#3644

Closed
evand wants to merge 4 commits intomanifoldmarkets:mainfrom
evand:fix/local-dev-schema-bugs
Closed

feat: Add LOCAL_ONLY mode for local development without Firebase/GCP#3644
evand wants to merge 4 commits intomanifoldmarkets:mainfrom
evand:fix/local-dev-schema-bugs

Conversation

@evand
Copy link
Contributor

@evand evand commented Dec 16, 2025

PR created entirely by Claude; zero human code review, only high-level functional checks.

Summary

Adds a LOCAL_ONLY mode that enables fully local Manifold development without requiring Firebase credentials or GCP access. This makes it possible to:

  • Run the API server against local Supabase
  • Create markets and place bets via API
  • Test bet calculations with dry-run
  • Run the web frontend with local auth bypass

Changes

Backend API - Accept X-Local-User header for auth when LOCAL_ONLY=true
Web Frontend - Auto-login as test user when NEXT_PUBLIC_LOCAL_ONLY=true
Common - Add setLocalOnlyUserId() for API auth headers
Supabase - Use SUPABASE_URL env var in local mode

Test plan

  • API server starts without Firebase errors
  • Can create markets via API with auth headers
  • Can place bets via API
  • Dry-run forecasting works
  • Web frontend auto-logs in as test user

Why this is useful

Enables contributors to test backend changes (AMM logic, bet calculations, schema changes) without needing privileged credentials.

Evan Daniel and others added 3 commits December 15, 2025 16:30
Enable fully local Manifold development using local Supabase (PostgreSQL).

## SQL Schema Fixes (21 files)
- seed.sql: Fix malformed comment syntax (lines 2, 4)
- answers.sql: Remove trailing comma before );
- 19 files: Change invalid `constraint primary key` to `primary key`

## LOCAL_ONLY Mode (API Server)
- serve.ts: Skip Firebase init and Secret Manager when LOCAL_ONLY=true
- init.ts: Support SUPABASE_HOST/SUPABASE_PORT env vars for local connection
- utils.ts: Handle LOCAL_ONLY in isProd() to avoid Firebase calls
- stripe-endpoints.ts: Lazy-init firestore to prevent import-time crash

## LOCAL_ONLY Mode (Scheduler)
- scheduler/utils.ts: Skip Firebase/Secret Manager init
- scheduler/index.ts: Skip METRIC_WRITER when LOCAL_ONLY

## New Files
- backend/api/.env.local.template: Environment template for local API
- backend/scheduler/.env.local.template: Environment template for scheduler
- backend/supabase/load-local-schema.sh: Script to load schema in correct order

## Usage
1. Start local Supabase: `cd backend/supabase && npx supabase start`
2. Load schema: `./load-local-schema.sh`
3. Copy template: `cd backend/api && cp .env.local.template .env.local`
4. Start server: `set -a && source .env.local && set +a && yarn dev`

Tested: API server connects to local PostgreSQL and serves data correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Enable web frontend to work with local Supabase in LOCAL_ONLY mode.

Changes:
- web/lib/supabase/admin-db.ts: Use SUPABASE_KEY env var in LOCAL_ONLY mode
- common/src/supabase/utils.ts: Use local Supabase REST API URL in LOCAL_ONLY mode

Usage:
1. Copy web/.env.local.template to web/.env.local (or set LOCAL_ONLY=true, SUPABASE_KEY)
2. Run: yarn dev:local

Note: May need to increase file watcher limit:
  sudo sysctl fs.inotify.max_user_watches=524288

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- auth-context.tsx: Skip Firebase, load test user directly from API
- api.ts: Add setLocalOnlyUserId() to include auth headers without Firebase
- endpoint.ts: Accept X-Local-User header in LOCAL_ONLY mode

Enables full local development workflow:
- Set NEXT_PUBLIC_LOCAL_ONLY=true in web/.env.local
- Set NEXT_PUBLIC_LOCAL_TEST_USER=<username>
- Frontend auto-logs in as test user, API calls work

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vercel
Copy link

vercel bot commented Dec 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
dev Ignored Ignored Preview Dec 16, 2025 5:10am

@vercel
Copy link

vercel bot commented Dec 16, 2025

Someone is attempting to deploy a commit to the Manifold Markets Team on Vercel.

A member of the Team first needs to authorize it.

Comprehensive step-by-step guide for running Manifold locally without
Firebase/GCP credentials. Covers:
- Quick wins (web frontend only, mock bet server)
- Full local stack with Supabase
- LOCAL_ONLY mode configuration
- Test data creation and betting verification
- Web frontend with auto-login
- Troubleshooting common issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@GabrielleVivissi
Copy link
Contributor

I ran into several issues, particularly around the contract created manually in the documentation. Here is a patch file with the fixes:

0001-Fix-misc-issues.patch

Things are still not working 100%, but it's roughly working

@ManiFed
Copy link
Contributor

ManiFed commented Jan 24, 2026

This is really cool!

@evand
Copy link
Contributor Author

evand commented Feb 19, 2026

Superseded by #3696, which is rebased on current main and incorporates the fixes from @GabrielleVivissi (thank you for the Supabase client config, auth context, and env var contributions!).

The new PR also resolves several additional issues discovered during testing:

  • Circular dependency in schema loading (functions.sql ↔ table SQL files)
  • 20 auto-generated SQL files with invalid constraint primary key syntax
  • Runtime Firebase dependencies in isProd() and stripe-endpoints.ts
  • Missing status_type enum and trailing comma in answers.sql

Thank you @ManiFed for the positive feedback on this PR!

Closing in favor of #3696.

@evand evand closed this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants