Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auth): recover mobile account boundaries
xd-bobo801c9cec167f
diff --git a/apps/mobile/src/__tests__/pushNotificationsRealm.test.ts b/apps/mobile/src/__tests__/pushNotificationsRealm.test.tsindex 98e4779f11..370f087fbb 100644--- a/apps/mobile/src/__tests__/pushNotificationsRealm.test.ts+++ b/apps/mobile/src/__tests__/pushNotificationsRealm.test.ts@@ -1,3 +1,5 @@+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';const store = vi.hoisted(() => new Map<string, string>());@@ -102,6 +104,21 @@ describe('push notification realm routing', () => {vi.unstubAllGlobals();});+ it('re-registers the restored owner after an account-switch rollback', () => {+ const source = readFileSync(+ resolve(process.cwd(), 'src/notifications/PushNotificationsBridge.tsx'),+ 'utf8',+ ).replace(/\r\n/g, '\n');+ const registrationStart = source.indexOf('// 登录态就绪后同步注册状态');+ const registrationBody = source.slice(+ registrationStart,+ source.indexOf('// APNs token 轮换', registrationStart),+ );++ expect(registrationBody).toContain('auth.accountGeneration');+ expect(registrationBody).toContain('syncPushRegistration(');+ });+it('向当前会话区域注册,但推送构建线仍保持安装包区域', async () => {envState.activeRealm = 'global';const apiFetch = vi.fn().mockResolvedValue({ registered: true });diff --git a/apps/mobile/src/auth/__tests__/mobileAccountVault.test.ts b/apps/mobile/src/auth/__tests__/mobileAccountVault.test.tsindex 0c569378ca..dcc4619229 100644--- a/apps/mobile/src/auth/__tests__/mobileAccountVault.test.ts+++ b/apps/mobile/src/auth/__tests__/mobileAccountVault.test.ts@@ -725,4 +725,25 @@ describe('mobile account vault', () => {expect.any(Number),);});++ it('lets explicit logout replace a malformed vault without parsing it', async () => {+ const malformed = '{bad-json';+ secureStorage.value = malformed;++ await expect(clearMobileAccountVault()).resolves.toBeUndefined();+ expect(parseMobileAccountVault(secureStorage.value)).toMatchObject({+ activeAccountKey: null,+ passports: {},+ resources: {},+ signedOutAt: expect.any(Number),+ });++ secureStorage.value = malformed;+ await expect(+ clearMobileAccountVault(async () => {+ throw new Error('session delete failed');+ }),+ ).rejects.toThrow('session delete failed');+ expect(secureStorage.value).toBe(malformed);+ });});diff --git a/apps/mobile/src/auth/mobileAccountVault.ts b/apps/mobile/src/auth/mobileAccountVault.tsindex 269e9ce4a5..a50d8ebfcf 100644--- a/apps/mobile/src/auth/mobileAccountVault.ts+++ b/apps/mobile/src/auth/mobileAccountVault.ts@@ -243,15 +243,22 @@ export function mutateMobileAccountVault<T>(export async function clearMobileAccountVault(afterPersist: () => void | Promise<void> = () => undefined,): Promise<void> {- await transactMobileAccountVault(- (vault) => {- vault.activeAccountKey = null;- vault.resources = {};- vault.passports = {};- vault.signedOutAt = Date.now();- },- afterPersist,- );+ await enqueueMobileVaultOperation(async () => {+ // Explicit logout is the one mutation allowed to replace malformed vault+ // contents. Preserve the opaque record for rollback, but do not require it+ // to parse before publishing the fail-closed signed-out owner.+ const raw = await getSecureItem(MOBILE_ACCOUNT_VAULT_KEY);+ const vault = emptyMobileAccountVault();+ vault.signedOutAt = Date.now();+ await writeMobileAccountVault(vault);+ try {+ await afterPersist();+ } catch (error) {+ if (raw === null) await deleteSecureItem(MOBILE_ACCOUNT_VAULT_KEY);+ else await setSecureItem(MOBILE_ACCOUNT_VAULT_KEY, raw);+ throw error;+ }+ });}export function listMobileSavedAccounts(vault: MobileAccountVault): MobileSavedAccount[] {diff --git a/apps/mobile/src/notifications/PushNotificationsBridge.tsx b/apps/mobile/src/notifications/PushNotificationsBridge.tsxindex 3d61f6f95a..5dd442b5a8 100644--- a/apps/mobile/src/notifications/PushNotificationsBridge.tsx+++ b/apps/mobile/src/notifications/PushNotificationsBridge.tsx@@ -65,7 +65,7 @@ export function PushNotificationsBridge() {return () => {cancelled = true;};- }, [auth.initialized, auth.isAuthenticated, auth.user]);+ }, [auth.accountGeneration, auth.initialized, auth.isAuthenticated, auth.user]);// APNs token 轮换 → 重新上报(仅开关开启且已登录时)useEffect(() => {