Skip to content

setup.sh broken: Firebase project mismatch after dev→staging migration #5939

Closed as not planned

Description

@beastoin

Summary

app/setup.sh is broken for new developer onboarding. The script configures the app with based-hardware-dev Firebase credentials, but the dev backend (api.omiapi.com) now verifies tokens against based-hardware (prod Firebase). Since Firebase ID tokens are project-scoped, every API call from a setup.sh-onboarded app returns 401 Unauthorized.

Root Cause

On Feb 19, 2026, commit a3b1efa (@kodjima33) changed the dev GKE backend to use GOOGLE_CLOUD_PROJECT=based-hardware (prod Firebase) for token verification. This was intentional — making dev behave as staging (dev API wired to prod database/Firebase for faster TestFlight verification).

However, app/setup.sh and its prebuilt configs were never updated to match:

Component Firebase Project File
setup/prebuilt/firebase_options.dart based-hardware-dev projectId: 'based-hardware-dev'
setup/prebuilt/google-services.json based-hardware-dev "project_id": "based-hardware-dev"
setup/prebuilt/GoogleService-Info.plist based-hardware-dev PROJECT_ID: based-hardware-dev
Dev backend (api.omiapi.com) based-hardware GOOGLE_CLOUD_PROJECT=based-hardware in Helm values

Token Verification Flow

  1. App signs user into based-hardware-dev Firebase → gets ID token scoped to based-hardware-dev
  2. App sends request to api.omiapi.com with Bearer token
  3. Backend calls firebase_admin.auth.verify_id_token(token) — initialized with GOOGLE_CLOUD_PROJECT=based-hardware
  4. Verification fails: token audience is based-hardware-dev, expected based-hardware → 401

Impact

  • All new developers running bash setup.sh ios or bash setup.sh android get a non-functional app
  • Sign-in succeeds (Firebase Auth works independently per project) but every subsequent API call fails
  • No error message explains the mismatch — developers see generic auth failures

Key Files

  • app/setup.sh (lines 52, 78-90) — sets API URL and copies prebuilt configs
  • app/setup/prebuilt/firebase_options.dart — projectId: 'based-hardware-dev'
  • app/setup/prebuilt/google-services.json — project_id: based-hardware-dev
  • app/setup/prebuilt/GoogleService-Info.plist — PROJECT_ID: based-hardware-dev
  • backend/charts/backend-listen/dev_omi_backend_listen_values.yaml (line 265-266) — GOOGLE_CLOUD_PROJECT: based-hardware

Fix Options

  1. Update prebuilt configs to based-hardware — regenerate all 3 prebuilt files against prod Firebase project. Simplest fix but requires prod Firebase access to generate configs.
  2. Add dual-project token verification — backend accepts tokens from both based-hardware-dev and based-hardware. More complex, maintains backward compatibility.
  3. Revert dev backend to based-hardware-dev — undo the staging migration. Not recommended since the migration was intentional for TestFlight workflow.

Option 1 is the recommended path — it aligns setup.sh with the current backend reality.

Activity

  1. added
    bug
    on Mar 23, 2026
  2. beastoin commented on Mar 23, 2026

    @beastoin
    CollaboratorAuthor

    Codex review confirms the analysis (gpt-5.3-codex, 130k tokens).

    Additional findings:

    • The pusher dev chart was also changed to GOOGLE_CLOUD_PROJECT=based-hardware in the same batch (commit 0ac298d92) — any fix must keep listen/pusher aligned.
    • setup.sh sets USE_AUTH_CUSTOM_TOKEN=true in .dev.env, which triggers the backend's /v1/auth/token custom token flow (firebase_admin.auth.create_custom_token()). This complicates option (b) (dual-project verification) because custom tokens generated against prod Firebase won't work for dev-project-signed-in users.
    • app/e2e/SKILL.md line 435 already documents this exact problem: "iOS simulator auth (dev Firebase tokens rejected by prod API — needs local backend)"

    Recommended fix path:

    1. Immediate stopgap — option (a): regenerate prebuilt configs against based-hardware (prod Firebase). Fastest unblock.
    2. Long-term — option (d): spin up a separate community-dev backend using based-hardware-dev Firebase, preserving staging parity on the main dev backend while restoring zero-friction onboarding.

    cc @kodjima33 — this broke when the dev→staging migration landed (Feb 19, a3b1efa).

  3. beastoin commented on Mar 23, 2026

    @beastoin
    CollaboratorAuthor

    Note: The fix recommendations above (options a–d) are Codex-generated suggestions only — not verified or approved by the CTO. Implementation should wait for CTO review and direction on the preferred approach.

  4. added
    p3
    on Mar 23, 2026
  5. formed2forge commented on Jun 25, 2026

    @formed2forge
    Contributor

    This continues to leave a large hurdle to get started developing / working on fixes on mobile for community developers. With the current state, not only does a community dev need to essentially spin up their own backend to just get past the auth hangup (certainly on iOS and presumably on Android as well), but with changes happening regularly on the omi backend, it also means that your community devs need to manage those backend changes in parallel while working on any mobile-related work. Solving this could only encourage community involvement in contributing meaningfully at the mobile-app level which is the primary entry-point to the OMI ecosystem for most people. I've worked out a solution based on what I can see from my end.

    Potential Fix + PR approach

    Following up on PR #5945 being closed — the Greptile review correctly identified it was incomplete (text-replace only updated projectId, leaving storageBucket and authDomain still pointing at based-hardware-dev). This comment documents the correct fix approach and a ready-to-use PR description.


    Why text-replace doesn't work

    The apiKey, appId, clientId, storageBucket, and authDomain values are all project-specific credentials that differ between based-hardware-dev and based-hardware. Only a full regeneration via FlutterFire CLI (or direct Firebase console download) produces correct values for all fields.


    Two broken paths — both need fixing

    setup.sh has two independent code paths, both broken:

    • Prebuilt path (setup_firebase()) — used by most community devs; copies files from setup/prebuilt/ to dev and prod flavor directories
    • Service account path (setup_firebase_with_service_account()) — used in CI when $FIREBASE_SERVICE_ACCOUNT_KEY is set; runs flutterfire config directly

    Fix: prebuilt path (Steps 1–3)

    Run this from inside the app/ directory (requires firebase login and Firebase console access to based-hardware):

    dart pub global activate flutterfire_cli
    
    flutterfire config \
      --project=based-hardware \
      --platforms=android,ios,web \
      --out=setup/prebuilt/firebase_options.dart \
      --android-app-id=com.friend.ios.dev \
      --android-out=setup/prebuilt/ \
      --ios-bundle-id=com.friend-app-with-wearable.ios12.development \
      --ios-out=setup/prebuilt/ \
      --ios-target=Runner \
      --yes

    This writes all three files (firebase_options.dart, GoogleService-Info.plist, google-services.json) into setup/prebuilt/ with correct credentials for all fields — including storageBucket, authDomain, and clientId.

    Important: Use flutterfire config (not configure). The configure subcommand writes platform files to default locations and can overwrite prod credentials in ios/Config/Prod/ and lib/firebase_options_prod.dart.

    If CLI access isn't available, the three files can also be downloaded manually from the Firebase console (based-hardware project → Project Settings → Your apps) for the com.friend.ios.dev (Android) and com.friend-app-with-wearable.ios12.development (iOS) apps.


    Fix: service account path (Step 4)

    In app/setup.sh, update both occurrences in setup_firebase_with_service_account:

    Line 105 (dev flavor):

    -    --project="based-hardware-dev" \
    +    --project="based-hardware" \

    Line 117 (prod flavor):

    -    --project="based-hardware-dev" \
    +    --project="based-hardware" \

    Note: $FIREBASE_SERVICE_ACCOUNT_KEY must also have IAM access to based-hardware (not just based-hardware-dev) for this path to work after the code change.


    PR description (ready to copy)

    fix: regenerate prebuilt Firebase configs against based-hardware project
    
    ## Summary
    
    - app/setup/prebuilt/firebase_options.dart — regenerated via FlutterFire CLI against based-hardware; fixes projectId, apiKey, appId, storageBucket, authDomain, and clientIds for all platforms
    - app/setup/prebuilt/google-services.json — replaced with download from based-hardware console (com.friend.ios.dev app)
    - app/setup/prebuilt/GoogleService-Info.plist — replaced with download from based-hardware console (com.friend-app-with-wearable.ios12.development app)
    - app/setup.sh lines 105, 117 — updated --project flag in setup_firebase_with_service_account from based-hardware-dev to based-hardware
    
    Note: The setup_firebase_with_service_account path also requires $FIREBASE_SERVICE_ACCOUNT_KEY
    to have IAM access to based-hardware (not just based-hardware-dev). That secret lives outside
    this repo; verify it is updated before enabling CI for the service account path.
    
    ## Root cause
    
    Commit a3b1efabb migrated the dev backend to GOOGLE_CLOUD_PROJECT=based-hardware (prod Firebase)
    for staging parity, but the prebuilt configs in app/setup/prebuilt/ were never updated. Firebase
    ID tokens are project-scoped — the app was signing users into based-hardware-dev, the backend
    was verifying against based-hardware, and every subsequent API call returned 401.
    
    ## Why the configs were regenerated (not text-replaced)
    
    The apiKey, appId, clientId, storageBucket, and authDomain values are all project-specific and
    differ between based-hardware-dev and based-hardware. Only a full regeneration via FlutterFire
    CLI (or direct Firebase console download) produces correct values for all fields.
    PR #5945 used text-replace and was correctly rejected by Greptile for leaving storageBucket
    and authDomain pointing at the old project.
    
    ## Test plan
    
    Prebuilt path (no service account — most community devs):
    - [ ] Run bash setup.sh ios from a clean checkout (no pre-existing Firebase configs)
    - [ ] Sign in — confirm auth succeeds
    - [ ] Make any API call against api.omiapi.com — confirm 200 response (not 401)
    - [ ] Run bash setup.sh android and repeat the above
    
    Service account path (CI / $FIREBASE_SERVICE_ACCOUNT_KEY set):
    - [ ] Confirm $FIREBASE_SERVICE_ACCOUNT_KEY has IAM access to based-hardware
    - [ ] Run bash setup.sh ios with the key exported — confirm flutterfire config completes without error
    - [ ] Confirm generated lib/firebase_options_dev.dart contains projectId: 'based-hardware' (not based-hardware-dev)
    
    Fixes #5939
    

    The fix itself requires someone with based-hardware Firebase console access — happy to test and refine the on-boarding script once it lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions