Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): retire add-account OAuth after restart
chenhong7bfdcd06a40a
diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsxindex 5509f589c8..73242da43c 100644--- a/apps/mobile/src/auth/AuthContext.tsx+++ b/apps/mobile/src/auth/AuthContext.tsx@@ -278,6 +278,7 @@ interface PendingOAuth {createdAt: number;label: string;realm: AuthRegion;+ additionalAccount?: boolean;}export interface AuthContextValue {@@ -1752,6 +1753,13 @@ export function AuthProvider({ children }: { children: ReactNode }) {}assertLoginFlowCurrent(expectedLoginFlowEpoch);if (oauthCancelledRef.current) throw authCodeError('AUTH_FLOW_SUPERSEDED');+ // Adding an account needs its live route and account context. After a+ // restart, keep the existing account rather than create a hidden flow.+ if (pending.additionalAccount && !additionalLoginRef.current) {+ oauthCancelledRef.current = true;+ await persistPendingOAuth(null);+ throw authCodeError('AUTH_FLOW_SUPERSEDED');+ }const concurrent = currentCompletion();if (concurrent) return concurrent;loginInitializationRef.current = null;@@ -1900,6 +1908,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {return null;});if (!isCurrent()) return false;+ if (pending?.additionalAccount && !additionalLoginRef.current) {+ oauthCancelledRef.current = true;+ await persistPendingOAuth(null);+ if (!isCurrent()) return false;+ }if (pending && !oauthCancelledRef.current) {// Retained credentials belong to the browser attempt. Restore its// cancelable wait screen instead of offering an unrelated login.@@ -1989,6 +2002,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {createdAt: Date.now(),label: input.label,realm: authorizationRealm,+ additionalAccount: additionalLoginRef.current,});assertLoginFlowCurrent(expectedLoginFlowEpoch);oauthCancelledRef.current = false;diff --git a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsxindex d388107eb4..4dbc442013 100644--- a/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx+++ b/apps/mobile/src/auth/__tests__/browserAuthSession.test.tsx@@ -395,6 +395,25 @@ describe('browser auth session lifecycle (real AuthProvider, mocked native/netwoexpect(auth.loginState?.step).toBe('sso-verification');});+ it.each(['initial-url', 'initialize'] as const)('does not restore an add-account attempt after restart (%s)', async entry => {+ await act(async () => { await auth.beginAddAccount(); });+ await start();+ const oldUrl = callbackUrl();+ if (entry === 'initial-url') native.initialUrl.mockResolvedValueOnce(oldUrl);+ await restartProvider();+ await mountLoginScreen('cold-add-account');+ expect(native.exchange).not.toHaveBeenCalled();+ expect(native.storage.has(pendingKey)).toBe(false);+ expect(auth.loginState?.step).toBe('identifier');+ await emitLink(oldUrl);+ expect(native.exchange).not.toHaveBeenCalled();+ await act(async () => { await auth.beginAddAccount(); });+ await start();+ await emitLink(callbackUrl());+ expect(native.exchange).toHaveBeenCalledTimes(1);+ 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();