Mobile login fix: bake API URL into builds, allow Capacitor origins, …#27
Merged
Merged
Conversation
…surface bad responses The Android (and iOS) APK was crashing on Sign in with "Cannot read properties of null (reading 'challenge')" because: 1. The web bundle inside the Capacitor shell defaulted apiFetch to `/api`, but Capacitor serves the bundle from https://localhost on Android (capacitor://localhost on iOS). The fetch hit the shell's own host, which returned the index.html via the SPA fallback, apiFetch silently returned null, and start.challenge blew up. 2. Even if the right host had been reached, the API's CORS layer only trusted the configured allowed_origins, so a Capacitor origin was rejected. 3. apiFetch swallowed the JSON parse failure (returning null on a 2xx with non-JSON body), which masked the real cause. Fixes: * The mobile workflows (android.yml, ios.yml) now resolve VITE_API_BASE and VITE_GATEWAY_URL from repository variables, falling back to apps/mobile/.env.production. Both values are exported to the env of the web build step so Vite bakes them into the bundle. Without this, every mobile login attempt 404s. * tempest-api always trusts https://localhost, http://localhost, capacitor://localhost, ionic://localhost, and tauri://localhost in addition to the configured web origin, so the mobile shells can authenticate without per-deploy CORS surgery. * apiFetch now throws a `bad_response` TempestError with a snippet of the body when a 2xx returns non-JSON or an empty body, instead of returning null and crashing the caller five lines later. apps/mobile/.env.production seeds the user's existing Railway URLs so fresh APK builds work out of the box; override via repo vars or by editing the file before tagging a release.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…surface bad responses
The Android (and iOS) APK was crashing on Sign in with "Cannot read properties of null (reading 'challenge')" because:
/api, but Capacitor serves the bundle from https://localhost on Android (capacitor://localhost on iOS). The fetch hit the shell's own host, which returned the index.html via the SPA fallback, apiFetch silently returned null, and start.challenge blew up.Fixes:
bad_responseTempestError with a snippet of the body when a 2xx returns non-JSON or an empty body, instead of returning null and crashing the caller five lines later.apps/mobile/.env.production seeds the user's existing Railway URLs so fresh APK builds work out of the box; override via repo vars or by editing the file before tagging a release.