mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 00:05:51 +00:00
fix: 修复初次登陆的校验问题
This commit is contained in:
@@ -148,9 +148,10 @@ export function Onboarding({ onDone }: Props): React.ReactNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const steps: OnboardingStep[] = []
|
const steps: OnboardingStep[] = []
|
||||||
if (oauthEnabled) {
|
// Preflight check disabled — users may use third-party API providers
|
||||||
steps.push({ id: 'preflight', component: preflightStep })
|
// if (oauthEnabled) {
|
||||||
}
|
// steps.push({ id: 'preflight', component: preflightStep })
|
||||||
|
// }
|
||||||
steps.push({ id: 'theme', component: themeStep })
|
steps.push({ id: 'theme', component: themeStep })
|
||||||
|
|
||||||
if (apiKeyNeedingApproval) {
|
if (apiKeyNeedingApproval) {
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
import axios from 'axios'
|
|
||||||
import React, { useEffect, useState } from 'react'
|
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 { useTimeout } from '../hooks/useTimeout.js'
|
||||||
import { Box, Text } from '@anthropic/ink'
|
import { Box, Text } from '@anthropic/ink'
|
||||||
import { getSSLErrorHint } from '../services/api/errorUtils.js'
|
import { Spinner } from '../components/Spinner.js'
|
||||||
import { getUserAgent } from './http.js'
|
|
||||||
import { logError } from './log.js'
|
|
||||||
|
|
||||||
export interface PreflightCheckResult {
|
export interface PreflightCheckResult {
|
||||||
success: boolean
|
success: boolean
|
||||||
@@ -16,66 +10,9 @@ export interface PreflightCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkEndpoints(): Promise<PreflightCheckResult> {
|
async function checkEndpoints(): Promise<PreflightCheckResult> {
|
||||||
try {
|
// Skip connectivity check — users may use third-party API providers
|
||||||
const oauthConfig = getOauthConfig()
|
// (OpenAI, Gemini, Grok, etc.) or be behind restricted networks.
|
||||||
const tokenUrl = new URL(oauthConfig.TOKEN_URL)
|
return { success: true }
|
||||||
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)}`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PreflightStepProps {
|
interface PreflightStepProps {
|
||||||
@@ -104,10 +41,8 @@ export function PreflightStep({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (result?.success) {
|
if (result?.success) {
|
||||||
onSuccess()
|
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])
|
}, [result, onSuccess])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -123,27 +58,6 @@ export function PreflightStep({
|
|||||||
<Box flexDirection="column" gap={1}>
|
<Box flexDirection="column" gap={1}>
|
||||||
<Text color="error">Unable to connect to Anthropic services</Text>
|
<Text color="error">Unable to connect to Anthropic services</Text>
|
||||||
<Text color="error">{result?.error}</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>
|
</Box>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user