Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): clear account boundary auth state
xd-bobo6635438a133c
diff --git a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.tsindex 62df5d38d8..20f6739282 100644--- a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts+++ b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts@@ -440,6 +440,58 @@ describe('mobile auth-server login', () => {expect(switchBody).not.toContain('const oldSession = initialVault');});+ it('clears the previous identity deletion receipt inside saved-account activation', () => {+ const authSource = readFileSync(+ resolve(process.cwd(), 'src/auth/AuthContext.tsx'),+ 'utf8',+ );+ const switchStart = authSource.indexOf('const switchAccount = useCallback');+ const switchBody = authSource.slice(+ switchStart,+ authSource.indexOf('\n\n const beginAddAccount', switchStart),+ );+ const runtimeClear = switchBody.indexOf(+ 'await clearAccountScopedRuntimeForSwitch();',+ );+ const receiptClear = switchBody.indexOf(+ 'await persistAccountDeletionReceipt(null);',+ runtimeClear,+ );+ const ownerCommit = switchBody.indexOf(+ 'activateMobileSessionRealm(realm!);',+ receiptClear,+ );++ expect(runtimeClear).toBeGreaterThan(-1);+ expect(receiptClear).toBeGreaterThan(runtimeClear);+ expect(ownerCommit).toBeGreaterThan(receiptClear);+ expect(switchBody.slice(receiptClear, ownerCommit)).toContain(+ 'pendingAccountDeletionRestoredRef.current = false;',+ );+ expect(switchBody.slice(receiptClear, ownerCommit)).toContain(+ 'setAccountDeletionRestored(false);',+ );+ });++ it('normalizes outer saved-account sync failures into sheet state', () => {+ const authSource = readFileSync(+ resolve(process.cwd(), 'src/auth/AuthContext.tsx'),+ 'utf8',+ );+ const syncStart = authSource.indexOf('const syncSavedAccounts = useCallback');+ const syncBody = authSource.slice(+ syncStart,+ authSource.indexOf('\n\n const switchAccount = useCallback', syncStart),+ );++ expect(syncBody).toContain('const generation = authGenerationRef.current;');+ expect(syncBody).toContain('} catch (error) {');+ expect(syncBody).toContain('setAccountsError(authErrorCode(error));');+ expect(syncBody).toContain(+ 'if (authGenerationRef.current === generation) setAccountsLoading(false);',+ );+ });+it('keeps the added-account vault transaction through runtime cleanup and owner commit', () => {const authSource = readFileSync(resolve(process.cwd(), 'src/auth/AuthContext.tsx'),diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsxindex 9a7f0a7a0d..c366fbe883 100644--- a/apps/mobile/src/auth/AuthContext.tsx+++ b/apps/mobile/src/auth/AuthContext.tsx@@ -1987,6 +1987,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {);const syncSavedAccounts = useCallback(async (): Promise<void> => {+ const generation = authGenerationRef.current;setAccountsLoading(true);setAccountsError(null);try {@@ -1997,7 +1998,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {} catch {// Keep the cached list on transient refresh failures.}- const generation = authGenerationRef.current;const vault = await readMobileAccountVault();let firstTransientError: string | null = null;for (const passport of Object.values(vault.passports)) {@@ -2030,8 +2030,15 @@ export function AuthProvider({ children }: { children: ReactNode }) {}await refreshSavedAccountsSnapshot();setAccountsError(firstTransientError);+ } catch (error) {+ // SecureStore/device-id/vault failures happen outside the per-Passport loop too.+ // Normalize them into the sheet's existing error projection so a fire-and-forget+ // refresh never reaches React Native's global unhandled-rejection handler.+ if (authGenerationRef.current === generation) {+ setAccountsError(authErrorCode(error));+ }} finally {- setAccountsLoading(false);+ if (authGenerationRef.current === generation) setAccountsLoading(false);}}, [refresh, refreshSavedAccountsSnapshot]);@@ -2165,6 +2172,17 @@ export function AuthProvider({ children }: { children: ReactNode }) {throw authCodeError('AUTH_FLOW_SUPERSEDED');}+ // The deletion receipt belongs to the previous login identity, not the+ // physical device. Clear its durable token, realm and restored banner at the+ // same account boundary as the other runtime projections. This is deliberately+ // the final awaited mutation before the synchronous owner commit below.+ await persistAccountDeletionReceipt(null);+ if (authGenerationRef.current !== generation) {+ throw authCodeError('AUTH_FLOW_SUPERSEDED');+ }+ pendingAccountDeletionRestoredRef.current = false;+ setAccountDeletionRestored(false);+// Publish the new owner synchronously while the vault// transaction still owns activeAccountKey and AUTH_SESSION_KEY.activateMobileSessionRealm(realm!);@@ -2218,6 +2236,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {applyUser,clearAccountScopedRuntimeForSwitch,loadMe,+ persistAccountDeletionReceipt,refreshSavedAccountsSnapshot,scheduleCanaryChannelSync,scheduleXdOrgBetaDefault,