Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auth): preserve foreign-device passports
xd-bobo4c333cea3632
diff --git a/apps/desktop/src/main/__tests__/authLoginFlowReset.test.ts b/apps/desktop/src/main/__tests__/authLoginFlowReset.test.tsindex a279a4ce7a..29660efc52 100644--- a/apps/desktop/src/main/__tests__/authLoginFlowReset.test.ts+++ b/apps/desktop/src/main/__tests__/authLoginFlowReset.test.ts@@ -343,6 +343,9 @@ describe('auth login-flow reset', () => {expect(helperBody).toContain('passportAccountRefreshFlights.get(key)');expect(helperBody).toContain('replacePassportSessionIfCurrent({');expect(helperBody).toContain('removePassportSessionIfCurrent(');+ expect(helperBody.indexOf("error.code === 'DEVICE_MISMATCH'")).toBeLessThan(+ helperBody.indexOf('removePassportSessionIfCurrent('),+ );expect(source).toContain("'write-failed'");expect(source).toContain("'CREDENTIAL_STORE_UNAVAILABLE'");expect(source).toContain('isPersistedSecretAbsent(AUTH_ACCOUNT_VAULT_KEY)');diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.tsindex 277a945950..13884b8fed 100644--- a/apps/desktop/src/main/authManager.ts+++ b/apps/desktop/src/main/authManager.ts@@ -1287,6 +1287,12 @@ async function refreshPassportSessionSingleFlight();return pair;} catch (error) {+ // A device mismatch only proves that this process is using a different+ // device identity. The encrypted Passport can still be valid for the+ // device that owns the shared vault, so it cannot authorize deletion.+ if (error instanceof AuthApiError && error.code === 'DEVICE_MISMATCH') {+ throw error;+ }if (isDefinitiveRefreshError(error)) {try {await removePassportSessionIfCurrent(realm, passportId, current.accountRefreshToken);diff --git a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.tsindex e6ee33f939..aa2c70acc6 100644--- a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts+++ b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts@@ -378,6 +378,9 @@ describe('mobile auth-server login', () => {expect(helperBody).toContain('mobilePassportRefreshFlights.get(key)');expect(helperBody).toContain('replaceMobilePassportSessionIfCurrent({');expect(helperBody).toContain('removeMobilePassportSessionIfCurrent(');+ expect(helperBody.indexOf("error.code === 'DEVICE_MISMATCH'")).toBeLessThan(+ helperBody.indexOf('removeMobilePassportSessionIfCurrent('),+ );const syncStart = authSource.indexOf('const syncSavedAccounts = useCallback',diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsxindex be5426e94a..6761a91c31 100644--- a/apps/mobile/src/auth/AuthContext.tsx+++ b/apps/mobile/src/auth/AuthContext.tsx@@ -183,6 +183,12 @@ async function refreshMobilePassportSingleFlight(if (!replacementStored) throw authCodeError('AUTH_FLOW_SUPERSEDED');return pair;} catch (error) {+ // A migrated vault or reset deviceId can make this process foreign to a+ // Passport that remains valid on its original device. Preserve it just+ // like the Resource refresh path does.+ if (error instanceof AuthApiError && error.code === 'DEVICE_MISMATCH') {+ throw error;+ }if (isDefinitivePassportSessionError(error)) {await removeMobilePassportSessionIfCurrent(realm,