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(mobile): abandon startup cleanup after OAuth mutations

chenhong0e31f79c1b49
diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsx
index da37bb4048..dbdf506a51 100644
--- a/apps/mobile/src/auth/AuthContext.tsx
+++ b/apps/mobile/src/auth/AuthContext.tsx
@@ -1452,9 +1452,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
// Authenticated cold starts can stay on Home without mounting LoginScreen.
// Retire only the old add-account attempt; never interfere with account
// recovery or a new login that has taken ownership during the storage read.
+ const pendingMutation = pendingOAuthMutationRef.current;
void (async () => {
const raw = await getSecureItem(PENDING_OAUTH_KEY);
if (cancelled || loginFlowEpochRef.current !== epoch || additionalLoginRef.current) return;
+ if (pendingOAuthMutationRef.current !== pendingMutation) return;
if (!raw || JSON.parse(raw)?.additionalAccount !== true) return;
oauthCancelledRef.current = true;
await persistPendingOAuth(null);
diff --git a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
index e56d693a58..30af729f7e 100644
--- a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
+++ b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
@@ -509,6 +509,31 @@ describe('browser auth session lifecycle (real AuthProvider, mocked native/netwo
expect(auth.isBusy).toBe(false);
});
+ it('does not retire a new ordinary login after a delayed startup read of an old add-account record', async () => {
+ await act(async () => { await auth.beginAddAccount(); });
+ await start();
+ const oldRecord = native.storage.get(pendingKey)!;
+ let finishRead!: () => void;
+ let delayed = false;
+ native.readSecure.mockImplementation(async (key: string) => {
+ if (key === pendingKey && !delayed) {
+ delayed = true;
+ return new Promise<string>(resolve => { finishRead = () => resolve(oldRecord); });
+ }
+ return native.storage.get(key) ?? null;
+ });
+ await restartProvider();
+ await mountLoginScreen('ordinary-cold-login');
+ expect(auth.loginState?.step).toBe('identifier');
+ await start('social');
+ const newRecord = native.storage.get(pendingKey);
+ expect(JSON.parse(newRecord!).additionalAccount).toBe(false);
+ await act(async () => { finishRead(); });
+ expect(native.storage.get(pendingKey)).toBe(newRecord);
+ await emitLink(callbackUrl());
+ expect(auth.loginState?.step).toBe('sso-verification');
+ });
+
it('explicit reset cancels the pending login; its late callback cannot authenticate', async () => {
await start();
const oldCallback = callbackUrl();