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): scope callback invalidation to browser login reset

chenhong58395327df81
diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsx
index 3f0d31427c..fa2a06faa0 100644
--- a/apps/mobile/src/auth/AuthContext.tsx
+++ b/apps/mobile/src/auth/AuthContext.tsx
@@ -1788,9 +1788,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const dispatchLoginAction = useCallback(
(action: MobileLoginAction): Promise<boolean> => {
- // Cancellation must invalidate callbacks already exchanging a code, before
- // any await or in-flight deduplication can attach reset to the old attempt.
- if (action.type === 'reset') loginFlowEpochRef.current += 1;
+ // Cancelling a browser login must invalidate its in-flight callback before
+ // any await or deduplication. Other login actions retain their lifecycle.
+ if (action.type === 'reset' && loginStateRef.current?.step === 'browser-redirect') {
+ loginFlowEpochRef.current += 1;
+ }
const expectedLoginFlowEpoch = loginFlowEpochRef.current;
suspendSessionRecoveryForLogin();
if (
diff --git a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
index 3f220dcfde..2da72a134f 100644
--- a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
+++ b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
@@ -239,6 +239,39 @@ describe('browser auth session lifecycle (real AuthProvider, mocked native/netwo
expect(native.storage.has(pendingKey)).toBe(false);
});
+ it('retains in-flight deduplication for reset outside browser authorization', async () => {
+ let first!: Promise<boolean>;
+ let second!: Promise<boolean>;
+ await act(async () => {
+ first = auth.dispatchLoginAction({ type: 'reset' });
+ second = auth.dispatchLoginAction({ type: 'reset' });
+ expect(second).toBe(first);
+ await first;
+ });
+ expect(auth.loginState?.step).toBe('identifier');
+ expect(auth.isBusy).toBe(false);
+ expect(native.exchange).not.toHaveBeenCalled();
+ });
+
+ it('invalidates an iOS browser callback on explicit reset without changing successful return handling', async () => {
+ native.platform = 'ios';
+ let complete!: (value: typeof verifiedOutcome) => void;
+ native.exchange.mockImplementation(() => new Promise(resolve => { complete = resolve; }));
+ native.open.mockImplementation(async () => ({ type: 'success', url: callbackUrl() }));
+ let cancelled!: Promise<unknown>;
+ await act(async () => {
+ cancelled = auth.dispatchLoginAction({ type: 'discover-sso-org', org: 'example.invalid' })
+ .catch(error => error);
+ });
+ expect(native.exchange).toHaveBeenCalledTimes(1);
+ await act(async () => { await auth.dispatchLoginAction({ type: 'reset' }); });
+ await act(async () => { complete(verifiedOutcome); await cancelled; });
+ expect(auth.loginState?.step).toBe('identifier');
+ expect(auth.authError).toBeNull();
+ expect(auth.isBusy).toBe(false);
+ expect(native.storage.has(pendingKey)).toBe(false);
+ });
+
it('keeps callback busy when Android dismiss arrives after the exchange has started', async () => {
let dismiss!: (value: { type: string }) => void;
let complete!: (value: typeof verifiedOutcome) => void;