fix(connection): fix 6 correctness bugs in auth/connect/diagnostics flow (#131)
1. buildRequestHeaders: UTF-8-encode Basic-auth credentials before btoa() so non-ASCII usernames/passwords don't throw (Hermes' btoa is Latin1-only and the throw was an unhandled rejection that hung the connect spinner). 2. diagnostics classify(): check root.ok (server reachable) before !internet.ok, so a reachable-but-failing server (e.g. wrong auth) is no longer misdiagnosed as "no internet" just because the public-internet probe also failed (captive portal, Tailscale-only network, etc). 3. sdk.ts createClient: strip trailing slashes from baseUrl once, so a trailing-slash URL from Advanced mode / Edit screen doesn't produce a double slash on every request path. 4. add.tsx / [id].tsx: wrap addConnection/updateConnection in try/catch so a SecureStore failure after a successful test resets the spinner and shows an alert instead of hanging forever. Adds connection.shared.alerts.saveFailedTitle/saveFailedMessage (en + zh-Hans). 5. add.tsx / [id].tsx: build the diagnostics probe's auth with buildAuth() instead of a hand-rolled expression, so the probe reproduces the real request's credentials (previously Quick Connect's password-only case sent no auth to the probe at all). 6. add.tsx handleQuickConnect: stop sending the shared `username` state, which could carry a stray value typed earlier in Advanced mode and silently override the "opencode" default after "Back to Quick". Claude-Session: https://claude.ai/code/session_01T12AhSnQVrSxNnvwfCx2z6 Co-authored-by: engineer <engineer@macbookpro.lan> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -245,6 +245,13 @@ async function fetchWithTimeout(url: string, options: RequestInit = {}, timeoutM
|
||||
}
|
||||
|
||||
export function createClient(config: ClientConfig) {
|
||||
// Normalize once: a trailing slash on baseUrl (e.g. pasted into Advanced
|
||||
// mode or the Edit screen) would otherwise survive into every
|
||||
// `${config.baseUrl}${path}` concatenation below as a double slash, which
|
||||
// every request then fails against (while the diagnostics probe, which
|
||||
// reconstructs a clean URL, reports "works now"). A bare URL with no
|
||||
// trailing slash is untouched.
|
||||
config = { ...config, baseUrl: config.baseUrl.replace(/\/+$/, "") }
|
||||
return {
|
||||
global: {
|
||||
// `timeoutMs` overrides the default REQUEST_TIMEOUT_MS — used by the
|
||||
|
||||
Reference in New Issue
Block a user