videogen/docs/runbooks/mobile-auth-scribase.md
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

7.6 KiB

Runbook: mobile sign-in on Scribase Auth (MN9)

The Menivor iOS and Android app signs creators in with Apple (and later Google) through an auth project that speaks the Supabase Auth API. Until now that project was the shared Supabase project psqkkdjzgptfcqpxuxki. MN9 moves it to Menivor's own project on Scribase (ereboslab/menivor/production). Scribase runs upstream GoTrue (supabase/gotrue:v2.196.0), so the app keeps using @supabase/supabase-js unchanged.

The money database is a separate move (MG9, Neon; infra-box/RUNBOOK-MENIVOR-NEON.md). The auth project holds only identities and public.profiles (schema in apps/mobile/scribase/migrations; the old menivor schema existed only to share the dead project). The old shared project is gone (NXDOMAIN, 2026-10-06), so there is no data to import.

How it fits together

  1. The app signs in with Apple on the Scribase project and gets an access token. Scribase projects sign it HS256 with the environment's JWT secret, with issuer <project URL>/auth/v1 and audience authenticated.
  2. The app calls POST /api/v1/auth/device with supabase_access_token. The API verifies the token in app/core/supabase_auth.verify_supabase_jwt: signature, issuer, audience and expiry.
  3. find_identity_user looks the account up by the subject, then by provider-verified email. A creator who already has a Menivor account (web, an older phone, or the old shared project) lands on that same account. There is no duplicate account and no second signup grant (MN3 rule: has_signup_grant and the grant markers). An unverified email never links to an existing account.

Tests: tests/reelforge/test_scribase_jwt.py. Its fixture tokens were minted by the pinned GoTrue image, run with the env Scribase writes for a project. apps/mobile/src/shared/auth/__tests__/supabase-config.test.ts covers which project the app picks.

Config

Where What Set by
apps/mobile/scribase/project.json + scribase/migrations/ project, Apple provider, profiles + delete_own_account() ~/products/deploy-scripts/scribase-move-apps.sh (owner-approved)
Box 1 /etc/products/menivor.env SUPABASE_URL = the project's public URL; SUPABASE_JWT_SECRET = its JWT secret (lines in infra-box/stacks/menivor/neon.env.example) owner
EAS environment variables EXPO_PUBLIC_SUPABASE_URL / _ANON_KEY (production, preview, development) and apps/mobile/.env.local the new project's URL and anon key (public values) scribase-move-apps.sh
apps/mobile/app.json expo.extra.auth optional override (url, anonKey); wins over the env when set. Left empty: nothing is hardcoded. release agent, only if needed

The JWT secret mints any token for the project, including service_role. Read it once from the Scribase console (api-keys?reveal=jwt_secret; owner or admin, with a fresh MFA code) and put it only in /etc/products/menivor.env. Never put it in the app.

Prod state on 2026-10-06 (old project gone)

psqkkdjzgptfcqpxuxki.supabase.co is NXDOMAIN. Read-only probes of api.menivor.com showed:

  • Mobile Apple/Google sign-in is broken end to end. The app cannot get a token at all, because its auth host is gone.
  • On the API side, POST /api/v1/auth/device with a sign-in token answers 503 in about 0.5 s. That route is _identity_claims in app/controllers/v1/device_auth.py. The 503 has one of two causes: SUPABASE_URL is not effectively configured (linking off), or the device secret is unset. The public message cannot tell them apart; docker logs on the box can.
  • GET /api/v1/me with any dummy bearer answers 401 (resolve_supabase_principal in app/core/auth/principal.py, then Clerk). If SUPABASE_URL still names the dead project, any real ES256 token would also fail there: the JWKS fetch to <url>/auth/v1/.well-known/jwks.json cannot resolve.
  • POST /api/v1/auth/device/challenge answers 404, so prod runs an older build than this branch.
  • Still works: web sign-in (Clerk), API keys, and guest device sessions.

Since the fail-safe change, an unreachable key host answers 503 ("sign-in is temporarily unavailable"), not 401. The fetch is bounded by SUPABASE_JWKS_TIMEOUT_SECONDS (default 3). For SUPABASE_JWKS_RETRY_SECONDS (default 30) after a failure, further requests fail fast with no network call. An unset SUPABASE_URL disables linking: /auth/device answers 503 for sign-in tokens, bearer auth falls through to Clerk, and one warning is logged at startup. A secret without a URL is not enough, because the issuer must be checked. Only HS256, ES256 and RS256 are accepted; alg=none and anything else are refused before any network call. The user id comes only from the verified sub.

Owner env change (box 1, /etc/products/menivor.env)

After scribase-move-apps.sh --only menivor has created ereboslab/menivor/production:

SUPABASE_URL=<the project URL printed by the script, no trailing slash>
SUPABASE_JWT_SECRET=<the environment JWT secret>   # only if the project signs user tokens HS256 (Scribase default)
# optional: SUPABASE_JWKS_TIMEOUT_SECONDS=3  SUPABASE_JWKS_RETRY_SECONDS=30

Then restart the API. The startup log line mobile sign-in: issuer <url>/auth/v1, HS256 on|off confirms the setting. Until that is done, you can instead remove the dead SUPABASE_URL line to get the clean 503 path.

Switch order

  1. PyJWT in the API image. requirements.txt pins PyJWT==2.15.1 (with cryptography), so the image already verifies tokens. Nothing to do.

  2. Scribase project. ~/products/deploy-scripts/scribase-move-apps.sh --only menivor creates the project, applies apps/mobile/scribase/migrations and writes the app env. If the project signs ES256 user tokens, SUPABASE_URL alone is enough for the API (JWKS); SUPABASE_JWT_SECRET is needed only for HS256.

  3. API. Put SUPABASE_URL and SUPABASE_JWT_SECRET in /etc/products/menivor.env and restart the API (build/build-menivor.sh or docker compose ... up -d api). Check it:

    # A token from the new project: sign in once on a dev build that has step 3's config
    curl -s -X POST https://api.menivor.com/api/v1/auth/device \
      -H 'content-type: application/json' \
      -d '{"install_id":"runbook-check-0000-0123456789","platform":"ios","supabase_access_token":"<token>"}'
    # -> 200 with "linked": true. 401 means the URL or the secret does not match the project.
    
  4. App. Ship a build with the EAS environment variables from step 1 (or an OTA update, where the runtime allows it). On first launch, the app removes the old project's stored session once, and the creator signs in with Apple again. They land on their existing account.

Before step 2, check whether the box already has SUPABASE_URL set. If it has none, sign-in linking was off: /auth/device answered 503 and installs used device sessions. Then no installed build loses anything at step 2. If it points at the old project, installs signed in there keep their device session after step 2. They re-link when they update to the build from step 3.

Rollback

  • API: restore the previous SUPABASE_URL and SUPABASE_JWT_SECRET (or remove them) and restart the API. Accounts are untouched; linking only reads them.
  • App: point the EAS EXPO_PUBLIC_SUPABASE_* variables back and rebuild (the old shared project no longer exists, so there is nothing older to fall back to).

Checks after the switch

  • A new Apple sign-in creates one account with one signup grant (credit_ledger reason mobile_identity_signup).
  • A creator with a web account signs in on the phone with the same verified email and sees the same balance.
  • The API log has no run of Supabase JWT verification failed.