fix(native): a signed-out first start no longer ends on Server not reachable

Connecting the app to a server as someone not signed in there showed
"Server not reachable" with the server up. The UI's first API call answered
401, the client redirected with a full page load while the first page was
still loading, WebKit cancelled that load (-999), and Capacitor answers every
failed navigation, a replaced one included, with its error page: the shell's
unreachable screen.

The client now waits for the first page to finish loading before such a
redirect inside the apps, which helps the binaries already out; and the iOS
shell puts a small navigation delegate in front of Capacitor's that lets a
cancelled or interrupted navigation pass without the error page.
This commit is contained in:
Maurice
2026-11-06 16:54:02 +01:00
parent 7e8e342e29
commit f81fe8cb17
3 changed files with 85 additions and 2 deletions
+20
View File
@@ -12,6 +12,8 @@ const { probeNow } = vi.hoisted(() => ({
probeNow: vi.fn(async (): Promise<'online' | 'offline' | 'proxy-wall'> => 'offline'),
}))
vi.mock('../sync/connectivity', () => ({ probeNow }))
const isNativeApp = vi.hoisted(() => vi.fn(() => false))
vi.mock('../native/platform', () => ({ isNativeApp }))
const { apiClient, adminApi, mapsApi, pluginsApi, parseInDev } = await import('./client')
@@ -357,6 +359,24 @@ describe('client > redirect handling', () => {
expect(loc.href).toBe('/login?redirect=' + encodeURIComponent('/trips/7?tab=map#day-2'))
})
it('FE-APIWIRE-019b: in the app it waits for the first page to finish loading before it leaves', async () => {
isNativeApp.mockReturnValue(true)
const ready = Object.getOwnPropertyDescriptor(Document.prototype, 'readyState')
Object.defineProperty(document, 'readyState', { value: 'loading', configurable: true })
const loc = setLocation('/dashboard')
server.use(http.get('/api/auth/me', () => HttpResponse.json({ code: 'AUTH_REQUIRED' }, { status: 401 })))
await captureError(() => apiClient.get('/auth/me'))
expect(loc.href).not.toContain('/login')
window.dispatchEvent(new Event('load'))
expect(loc.href).toBe('/login?redirect=' + encodeURIComponent('/dashboard'))
delete (document as { readyState?: unknown }).readyState
if (ready) Object.defineProperty(Document.prototype, 'readyState', ready)
isNativeApp.mockReturnValue(false)
})
it('FE-APIWIRE-020: an MFA_REQUIRED 403 sends the user to the settings page', async () => {
const loc = setLocation('/dashboard')
server.use(http.get('/api/auth/me', () => HttpResponse.json({ code: 'MFA_REQUIRED' }, { status: 403 })))