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): release browser action on terminal OAuth callbacks

chenhong5a9b25c839a4
diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsx
index dbdf506a51..70ff654f28 100644
--- a/apps/mobile/src/auth/AuthContext.tsx
+++ b/apps/mobile/src/auth/AuthContext.tsx
@@ -1825,6 +1825,12 @@ export function AuthProvider({ children }: { children: ReactNode }) {
if (loginFlowEpochRef.current !== expectedLoginFlowEpoch) throw error;
const code = authErrorCode(error);
if (!parsedCallback) {
+ // Terminal Linking results own the error/retry screen just as a
+ // successful exchange owns its continuation, even during cleanup.
+ if (loginActionInFlightRef.current === browserAction) {
+ loginActionInFlightRef.current = null;
+ loginActionInFlightEpochRef.current = null;
+ }
oauthCancelledRef.current = true;
let reportedCode = code;
try {
diff --git a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
index 30af729f7e..ca93f030fb 100644
--- a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
+++ b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx
@@ -534,6 +534,27 @@ describe('browser auth session lifecycle (real AuthProvider, mocked native/netwo
expect(auth.loginState?.step).toBe('sso-verification');
});
+ it.each(['cancel', 'dismiss', 'success'] as const)('preserves a terminal Linking error when the browser later returns %s', async type => {
+ native.platform = 'ios';
+ let finishBrowser!: (value: {type: string; url?: string}) => void;
+ native.open.mockImplementationOnce(() => new Promise(resolve => { finishBrowser = resolve; }));
+ let opening!: Promise<unknown>;
+ await act(async () => { opening = auth.dispatchLoginAction({type: 'start-social-browser', provider: 'wechat', label: 'WeChat'}).catch(e => e); });
+ const errorUrl = callbackUrl().replace('code=fixture-code', 'error=access_denied');
+ await emitLink(errorUrl);
+ const errorState = auth.loginState;
+ expect(errorState?.step).toBe('error');
+ await act(async () => { finishBrowser({type, url: errorUrl}); await opening; });
+ expect(auth.loginState).toBe(errorState);
+ expect(auth.authError).toBe('access_denied');
+ expect(native.exchange).not.toHaveBeenCalled();
+ await act(async () => { await auth.dispatchLoginAction({type: 'reset'}); });
+ native.platform = 'android';
+ await start();
+ 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();