Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(auth): surface mobile credential failures

xd-boboe09f0f71cb66
diff --git a/apps/mobile/app/(auth)/login.tsx b/apps/mobile/app/(auth)/login.tsx
index 8d7fbfc06e..256a4429a4 100644
--- a/apps/mobile/app/(auth)/login.tsx
+++ b/apps/mobile/app/(auth)/login.tsx
@@ -352,7 +352,7 @@ export function LoginScreen({
if (cancelled || !status) return;
if (status.status === 'cancelled') {
stopPolling();
- await auth.clearAccountDeletionReceipt();
+ await auth.clearAccountDeletionReceipt().catch(() => undefined);
if (!cancelled) setAccountDeletionStatus(null);
return;
}
@@ -364,7 +364,7 @@ export function LoginScreen({
cause.code === 'ACCOUNT_DELETION_RECEIPT_INVALID'
) {
stopPolling();
- await auth.clearAccountDeletionReceipt();
+ await auth.clearAccountDeletionReceipt().catch(() => undefined);
} else if (
cause instanceof AuthApiError &&
cause.code === 'INVALID_RESPONSE'
@@ -1429,7 +1429,7 @@ export function LoginScreen({
frame={deletionBubbleFrame}
onDismiss={
accountDeletionStatus.status === 'completed'
- ? () => void auth.clearAccountDeletionReceipt()
+ ? () => void auth.clearAccountDeletionReceipt().catch(() => undefined)
: undefined
}
status={accountDeletionStatus}
diff --git a/apps/mobile/app/devices/index.tsx b/apps/mobile/app/devices/index.tsx
index fd9a5db412..4c3904557f 100644
--- a/apps/mobile/app/devices/index.tsx
+++ b/apps/mobile/app/devices/index.tsx
@@ -2,6 +2,7 @@ import { useFocusEffect } from 'expo-router';
import { Fragment, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type MutableRefObject, type ReactNode } from 'react';
import {
ActivityIndicator,
+ Alert,
Animated,
Easing,
Modal,
@@ -1435,10 +1436,12 @@ export default function HomeScreen() {
setLoggingOut(true);
try {
await auth.logout();
+ } catch (error) {
+ Alert.alert(t('devices.list.alert.actionFailed'), formatRemoteError(error));
} finally {
setLoggingOut(false);
}
- }, [auth, loggingOut]);
+ }, [auth, loggingOut, t]);
const toggleProject = useCallback((key: string) => {
configureCollapseAnimation();
diff --git a/apps/mobile/app/settings.tsx b/apps/mobile/app/settings.tsx
index f4ff258441..43bd462fc5 100644
--- a/apps/mobile/app/settings.tsx
+++ b/apps/mobile/app/settings.tsx
@@ -548,10 +548,12 @@ export default function SettingsScreen() {
try {
await auth.logout();
router.replace('/login');
+ } catch (error) {
+ Alert.alert(t('devices.list.alert.actionFailed'), formatRemoteError(error));
} finally {
setLoggingOut(false);
}
- }, [auth, loggingOut, router]);
+ }, [auth, loggingOut, router, t]);
const switchDevServerEnvironment = useCallback(
async (next: DevServerEnvironment) => {
diff --git a/apps/mobile/src/__tests__/accountDeletion.test.ts b/apps/mobile/src/__tests__/accountDeletion.test.ts
index 7635f4b3fa..9d834e2b96 100644
--- a/apps/mobile/src/__tests__/accountDeletion.test.ts
+++ b/apps/mobile/src/__tests__/accountDeletion.test.ts
@@ -68,6 +68,19 @@ describe("mobile account deletion", () => {
expect(context).toContain(
"serializeAccountDeletionReceiptRecord(realm, receiptToken)",
);
+ const persistStart = context.indexOf(
+ "const persistAccountDeletionReceipt = useCallback",
+ );
+ const persistBody = context.slice(
+ persistStart,
+ context.indexOf("/* ── 登录人机验证", persistStart),
+ );
+ expect(persistBody).toContain(
+ "await deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY);",
+ );
+ expect(persistBody).not.toContain(
+ "deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY).catch",
+ );
expect(requestBody).toContain("activeAuthRealmRef.current,\n );");
expect(confirmBody).toContain("await clearLocalSession();");
expect(confirmBody).not.toContain(
diff --git a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
index 08c572fd23..6736a51f61 100644
--- a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
@@ -46,6 +46,19 @@ describe('mobile Home startup reads', () => {
});
describe('mobile home desktop-first surface', () => {
+ it('surfaces durable logout failures from the home drawer', () => {
+ const source = readSource('app/devices/index.tsx');
+ const logoutStart = source.indexOf('const logout = useCallback');
+ const logoutBody = source.slice(
+ logoutStart,
+ source.indexOf('const toggleProject', logoutStart),
+ );
+
+ expect(logoutBody).toContain('await auth.logout();');
+ expect(logoutBody).toContain("t('devices.list.alert.actionFailed')");
+ expect(logoutBody).toContain('formatRemoteError(error)');
+ });
+
it('uses the desktop-sidebar Home as the authenticated root instead of a device picker route', () => {
const indexSource = readSource('app/index.tsx');
const layoutSource = readSource('app/_layout.tsx');
diff --git a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
index 5ae5f88916..6db3e29c84 100644
--- a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
+++ b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
@@ -656,6 +656,9 @@ describe('mobile auth-server login', () => {
expect(sheetSource).not.toContain(
'disabled={auth.accountsLoading || switchingKey !== null}',
);
+ expect(sheetSource).toContain("t('devices.list.alert.actionFailed')");
+ expect(sheetSource).toContain('formatRemoteError(error)');
+ expect(sheetSource).not.toContain('.catch(() => undefined)\n .finally');
});
it('clears every Device Link account projection when accountGeneration changes', () => {
diff --git a/apps/mobile/src/__tests__/mobileSettings.test.ts b/apps/mobile/src/__tests__/mobileSettings.test.ts
index a39502bf7c..0bc84654a8 100644
--- a/apps/mobile/src/__tests__/mobileSettings.test.ts
+++ b/apps/mobile/src/__tests__/mobileSettings.test.ts
@@ -15,6 +15,22 @@ const readTextLf = (...args: Parameters<typeof readFileSync>): string =>
String(readFileSync(...args)).replace(/\r\n/g, '\n');
describe('mobile settings overview', () => {
+ it('surfaces durable logout failures instead of dropping the promise', () => {
+ const settingsSource = readTextLf(
+ resolve(process.cwd(), 'app/settings.tsx'),
+ 'utf8',
+ );
+ const logoutStart = settingsSource.indexOf('const logout = useCallback');
+ const logoutBody = settingsSource.slice(
+ logoutStart,
+ settingsSource.indexOf('const switchDevServerEnvironment', logoutStart),
+ );
+
+ expect(logoutBody).toContain('await auth.logout();');
+ expect(logoutBody).toContain("t('devices.list.alert.actionFailed')");
+ expect(logoutBody).toContain('formatRemoteError(error)');
+ });
+
it('renders language as one expandable picker instead of a fixed option list', () => {
const source = readTextLf(resolve(process.cwd(), 'app/settings.tsx'), 'utf8');
diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsx
index 0547629884..5e15227534 100644
--- a/apps/mobile/src/auth/AuthContext.tsx
+++ b/apps/mobile/src/auth/AuthContext.tsx
@@ -629,9 +629,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
);
accountDeletionReceiptRealmRef.current = realm;
} else {
- await deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY).catch(
- () => undefined,
- );
+ // Account-bound transitions await this helper before publishing the
+ // new owner. A failed durable delete must reject so their vault and
+ // active-session transactions roll back instead of reviving the
+ // previous identity's receipt after restart.
+ await deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY);
accountDeletionReceiptRealmRef.current = null;
}
setAccountDeletionReceipt(receiptToken);
diff --git a/apps/mobile/src/session/AccountSwitcherSheet.tsx b/apps/mobile/src/session/AccountSwitcherSheet.tsx
index ec4d92f1bf..1e0f09de67 100644
--- a/apps/mobile/src/session/AccountSwitcherSheet.tsx
+++ b/apps/mobile/src/session/AccountSwitcherSheet.tsx
@@ -14,6 +14,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useAuth } from '@/auth/AuthContext';
import { Text } from '@/components/AppText';
+import { formatRemoteError } from '@/device-link/remoteStatus';
import { computeContextSheetSnapHeights, type ContextSheetSnap } from '@/session/contextSheetModel';
import { SheetModal } from '@/session/SheetModal';
import { SheetSurface } from '@/session/SheetSurface';
@@ -62,7 +63,7 @@ export function AccountSwitcherSheet({
useEffect(() => {
if (!visible) return;
setSnap('half');
- void auth.syncSavedAccounts();
+ void auth.syncSavedAccounts().catch(() => undefined);
}, [auth.syncSavedAccounts, visible]);
const confirmBoundary = (action: () => void) => {
@@ -90,7 +91,9 @@ export function AccountSwitcherSheet({
void auth
.switchAccount(accountKey)
.then(onClose)
- .catch(() => undefined)
+ .catch((error) => {
+ Alert.alert(t('devices.list.alert.actionFailed'), formatRemoteError(error));
+ })
.finally(() => setSwitchingKey(null));
});
};