mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
fix: 修复初次登陆的校验问题
This commit is contained in:
@@ -148,9 +148,10 @@ export function Onboarding({ onDone }: Props): React.ReactNode {
|
||||
}
|
||||
|
||||
const steps: OnboardingStep[] = []
|
||||
if (oauthEnabled) {
|
||||
steps.push({ id: 'preflight', component: preflightStep })
|
||||
}
|
||||
// Preflight check disabled — users may use third-party API providers
|
||||
// if (oauthEnabled) {
|
||||
// steps.push({ id: 'preflight', component: preflightStep })
|
||||
// }
|
||||
steps.push({ id: 'theme', component: themeStep })
|
||||
|
||||
if (apiKeyNeedingApproval) {
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { logEvent } from 'src/services/analytics/index.js'
|
||||
import { Spinner } from '../components/Spinner.js'
|
||||
import { getOauthConfig } from '../constants/oauth.js'
|
||||
import { useTimeout } from '../hooks/useTimeout.js'
|
||||
import { Box, Text } from '@anthropic/ink'
|
||||
import { getSSLErrorHint } from '../services/api/errorUtils.js'
|
||||
import { getUserAgent } from './http.js'
|
||||
import { logError } from './log.js'
|
||||
import { Spinner } from '../components/Spinner.js'
|
||||
|
||||
export interface PreflightCheckResult {
|
||||
success: boolean
|
||||
@@ -16,66 +10,9 @@ export interface PreflightCheckResult {
|
||||
}
|
||||
|
||||
async function checkEndpoints(): Promise<PreflightCheckResult> {
|
||||
try {
|
||||
const oauthConfig = getOauthConfig()
|
||||
const tokenUrl = new URL(oauthConfig.TOKEN_URL)
|
||||
const endpoints = [
|
||||
`${oauthConfig.BASE_API_URL}/api/hello`,
|
||||
`${tokenUrl.origin}/v1/oauth/hello`,
|
||||
]
|
||||
|
||||
const checkEndpoint = async (
|
||||
url: string,
|
||||
): Promise<PreflightCheckResult> => {
|
||||
try {
|
||||
const response = await axios.get(url, {
|
||||
headers: { 'User-Agent': getUserAgent() },
|
||||
})
|
||||
if (response.status !== 200) {
|
||||
const hostname = new URL(url).hostname
|
||||
return {
|
||||
success: false,
|
||||
error: `Failed to connect to ${hostname}: Status ${response.status}`,
|
||||
}
|
||||
}
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
const hostname = new URL(url).hostname
|
||||
const sslHint = getSSLErrorHint(error)
|
||||
return {
|
||||
success: false,
|
||||
error: `Failed to connect to ${hostname}: ${error instanceof Error ? (error as ErrnoException).code || error.message : String(error)}`,
|
||||
sslHint: sslHint ?? undefined,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const results = await Promise.all(endpoints.map(checkEndpoint))
|
||||
const failedResult = results.find(result => !result.success)
|
||||
|
||||
if (failedResult) {
|
||||
// Log failure to Statsig
|
||||
logEvent('tengu_preflight_check_failed', {
|
||||
isConnectivityError: false,
|
||||
hasErrorMessage: !!failedResult.error,
|
||||
isSSLError: !!failedResult.sslHint,
|
||||
})
|
||||
}
|
||||
|
||||
return failedResult || { success: true }
|
||||
} catch (error) {
|
||||
logError(error as Error)
|
||||
|
||||
// Log to Statsig
|
||||
logEvent('tengu_preflight_check_failed', {
|
||||
isConnectivityError: true,
|
||||
})
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: `Connectivity check error: ${error instanceof Error ? (error as ErrnoException).code || error.message : String(error)}`,
|
||||
}
|
||||
}
|
||||
// Skip connectivity check — users may use third-party API providers
|
||||
// (OpenAI, Gemini, Grok, etc.) or be behind restricted networks.
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
interface PreflightStepProps {
|
||||
@@ -104,10 +41,8 @@ export function PreflightStep({
|
||||
useEffect(() => {
|
||||
if (result?.success) {
|
||||
onSuccess()
|
||||
} else if (result && !result.success) {
|
||||
const timer = setTimeout(() => process.exit(1), 100)
|
||||
return () => clearTimeout(timer)
|
||||
}
|
||||
// Failure branch removed — preflight check always succeeds
|
||||
}, [result, onSuccess])
|
||||
|
||||
return (
|
||||
@@ -123,27 +58,6 @@ export function PreflightStep({
|
||||
<Box flexDirection="column" gap={1}>
|
||||
<Text color="error">Unable to connect to Anthropic services</Text>
|
||||
<Text color="error">{result?.error}</Text>
|
||||
{result?.sslHint ? (
|
||||
<Box flexDirection="column" gap={1}>
|
||||
<Text>{result.sslHint}</Text>
|
||||
<Text color="suggestion">
|
||||
See https://code.claude.com/docs/en/network-config
|
||||
</Text>
|
||||
</Box>
|
||||
) : (
|
||||
<Box flexDirection="column" gap={1}>
|
||||
<Text>
|
||||
Please check your internet connection and network settings.
|
||||
</Text>
|
||||
<Text>
|
||||
Note: Claude Code might not be available in your country.
|
||||
Check supported countries at{' '}
|
||||
<Text color="suggestion">
|
||||
https://anthropic.com/supported-countries
|
||||
</Text>
|
||||
</Text>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user