Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): hide WeChat login when unavailable on iOS
xd-bobo221ced06220f
diff --git a/apps/mobile/app/(auth)/login.tsx b/apps/mobile/app/(auth)/login.tsxindex 4e31356e3a..66f48d6433 100644--- a/apps/mobile/app/(auth)/login.tsx+++ b/apps/mobile/app/(auth)/login.tsx@@ -2,7 +2,17 @@ import { Stack } from 'expo-router';import { X } from 'lucide-react-native';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';-import { Animated, Easing, Keyboard, Linking, Platform, Pressable, StyleSheet, View } from 'react-native';+import {+ Animated,+ AppState,+ Easing,+ Keyboard,+ Linking,+ Platform,+ Pressable,+ StyleSheet,+ View,+} from 'react-native';import { useSafeAreaInsets } from 'react-native-safe-area-context';import type { AccountDeletionStatus, SocialProvider, VerificationKind } from '@cindy/auth-client';@@ -25,7 +35,10 @@ import { authErrorText, getAuthLocale, loginText } from '@/auth/loginMessages';import { canResumePendingConsent, makeConsentStamp, type ConsentStamp } from '@/auth/consentGate';import { acceptPrivacyConsent } from '@/analytics/analyticsConsentStore';import { initMobileTapdb } from '@/analytics/mobileTapdb';-import { isNativeSocialProviderSupported } from '@/auth/nativeSocial';+import {+ isNativeSocialProviderAvailable,+ isNativeSocialProviderSupported,+} from '@/auth/nativeSocial';import {resolveMobileSocialLoginMode,type MobileSocialLoginMode,@@ -278,6 +291,7 @@ export function LoginScreen({const [accountDeletionStatus, setAccountDeletionStatus] =useState<AccountDeletionStatus | null>(null);const [accountSwitcherVisible, setAccountSwitcherVisible] = useState(false);+ const [iosWechatAvailable, setIosWechatAvailable] = useState(false);const styles = useThemedStyles(makeStyles);const configIssues = getMobileConfigIssues();const disabled = auth.isBusy || !auth.initialized || configIssues.length > 0;@@ -292,6 +306,23 @@ export function LoginScreen({};}, []);+ useEffect(() => {+ if (Platform.OS !== 'ios') return;+ let cancelled = false;+ const refresh = async () => {+ const available = await isNativeSocialProviderAvailable('wechat');+ if (!cancelled) setIosWechatAvailable(available);+ };+ void refresh();+ const subscription = AppState.addEventListener('change', (state) => {+ if (state === 'active') void refresh();+ });+ return () => {+ cancelled = true;+ subscription.remove();+ };+ }, []);+useEffect(() => {if (!ssoOrgMode || ssoOrgEditedRef.current || ssoOrgHistory.length === 0)return;@@ -465,7 +496,10 @@ export function LoginScreen({provider,region: BUILD_AUTH_REGION,platform: Platform.OS,- nativeSupported: isNativeSocialProviderSupported(provider),+ nativeSupported:+ provider === 'wechat' && Platform.OS === 'ios'+ ? iosWechatAvailable+ : isNativeSocialProviderSupported(provider),});if (mode) socialProviderModes.set(provider, mode);}diff --git a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.tsindex 1ceb165dd0..4243e81966 100644--- a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts+++ b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts@@ -55,6 +55,12 @@ describe('mobile auth-server login', () => {);expect(nativeSource).toContain('GoogleSignin.configure({');expect(nativeSource).toContain("import('xdt-wechat-login')");+ expect(loginSource).toContain(+ "isNativeSocialProviderAvailable('wechat')",+ );+ expect(loginSource).toContain(+ "provider === 'wechat' && Platform.OS === 'ios'",+ );expect(nativeSource).toContain('requestWechatAuthCode({');expect(nativeSource).toContain('createNativeWechatLoginTimeout()');expect(nativeSource).toContain('cancelWechatAuthRequest().catch');diff --git a/apps/mobile/src/auth/__tests__/nativeWechatLogin.test.ts b/apps/mobile/src/auth/__tests__/nativeWechatLogin.test.tsindex 03a7f947ea..8ab7b07bba 100644--- a/apps/mobile/src/auth/__tests__/nativeWechatLogin.test.ts+++ b/apps/mobile/src/auth/__tests__/nativeWechatLogin.test.ts@@ -36,7 +36,11 @@ vi.mock('xdt-wechat-login', () => ({cancelWechatAuthRequest: native.cancel,}));-import { acquireNativeSocialCredential, isNativeSocialProviderSupported } from '../nativeSocial';+import {+ acquireNativeSocialCredential,+ isNativeSocialProviderAvailable,+ isNativeSocialProviderSupported,+} from '../nativeSocial';function changeAppState(state: string) {native.appState = state;@@ -61,6 +65,28 @@ afterEach(() => {});describe('native WeChat credential acquisition', () => {+ it('offers WeChat on iOS only when the companion app is installed', async () => {+ await expect(isNativeSocialProviderAvailable('wechat')).resolves.toBe(true);+ native.installed.mockResolvedValue(false);+ await expect(isNativeSocialProviderAvailable('wechat')).resolves.toBe(+ false,+ );+ });++ it('keeps the configured WeChat entry visible on Android without probing installation', async () => {+ native.platform = 'android';+ native.installed.mockResolvedValue(false);+ await expect(isNativeSocialProviderAvailable('wechat')).resolves.toBe(+ true,+ );+ expect(native.installed).not.toHaveBeenCalled();+ });++ it('hides WeChat on iOS when the installation probe fails', async () => {+ native.installed.mockRejectedValue(new Error('native bridge unavailable'));+ await expect(isNativeSocialProviderAvailable('wechat')).resolves.toBe(false);+ });+it.each(['ios', 'android'])('acquires only an authorization code on %s', async (platform) => {native.platform = platform;expect(isNativeSocialProviderSupported('wechat')).toBe(true);@@ -77,6 +103,7 @@ describe('native WeChat credential acquisition', () => {it('does not launch WeChat when public configuration is missing', async () => {native.appId = '';expect(isNativeSocialProviderSupported('wechat')).toBe(false);+ await expect(isNativeSocialProviderAvailable('wechat')).resolves.toBe(false);await expect(acquireNativeSocialCredential('wechat')).rejects.toMatchObject({code: 'SOCIAL_PROVIDER_NOT_CONFIGURED',});diff --git a/apps/mobile/src/auth/nativeSocial.ts b/apps/mobile/src/auth/nativeSocial.tsindex c6115fce6b..69b68d0c2f 100644--- a/apps/mobile/src/auth/nativeSocial.ts+++ b/apps/mobile/src/auth/nativeSocial.ts@@ -47,6 +47,26 @@ export function isNativeSocialProviderSupported(return !!WECHAT_APP_ID && !!WECHAT_UNIVERSAL_LINK;}+/**+ * Resolves whether a configured native provider should be offered on this+ * device. WeChat's iOS flow requires the companion app, so App Review builds+ * hide that entry when the SDK cannot find WeChat. Android keeps the entry and+ * reports an unavailable provider after a tap, matching the platform's normal+ * install flow.+ */+export async function isNativeSocialProviderAvailable(+ provider: SocialProvider,+): Promise<boolean> {+ if (!isNativeSocialProviderSupported(provider)) return false;+ if (provider !== 'wechat' || Platform.OS !== 'ios') return true;+ try {+ const { isWechatInstalled } = await import('xdt-wechat-login');+ return await isWechatInstalled();+ } catch {+ return false;+ }+}+/** Acquires a short-lived native SDK credential. Token exchange always happens in auth-server. */export async function acquireNativeSocialCredential(provider: SocialProvider,diff --git a/docs/dev-rules/mobile-development.md b/docs/dev-rules/mobile-development.mdindex f1afef27ab..1426f10948 100644--- a/docs/dev-rules/mobile-development.md+++ b/docs/dev-rules/mobile-development.md@@ -95,6 +95,8 @@ pnpm --filter mobile test:smoke仅 OTA 无法添加回调配置;按下方冷更规则比对 fingerprint。- 真机验证 iOS Universal Link/AASA、Android 包名/签名与 WXEntryActivity,覆盖同意授权、取消、未安装微信、回到前台超时后重试。iOS Simulator 不支持微信授权。+ iOS 登录页仅在 OpenSDK 确认已安装微信后显示微信入口;Android 保持入口可见,点击时+ 再由原生桥确认微信是否可用。凭据获取前仍须二次检查安装状态,不能只依赖页面显隐。未绑手机号须短信验证,已绑用户免短信;用同一微信在 PC 和两种手机上确认账号一致。- 模拟器与真机排错: