Refactor SupabaseSettingsForm component
The SupabaseSettingsForm component was refactored into smaller, more manageable components to improve readability and maintainability.
This commit is contained in:
@@ -1,88 +1,55 @@
|
||||
|
||||
import { supabase } from '../client';
|
||||
import { testAuthService } from './authTests';
|
||||
import { testAuth } from './authTests';
|
||||
import { testRestApi } from './apiTests';
|
||||
import { testDatabase } from './databaseTests';
|
||||
import { testDatabaseConnection } from './databaseTests';
|
||||
import { TestResults } from './types';
|
||||
import { supabase, isValidUrl } from '../client';
|
||||
import { getSupabaseUrl, getSupabaseKey, isCorsProxyEnabled, getProxyType } from '../config';
|
||||
|
||||
export const testSupabaseConnection = async () => {
|
||||
console.log('Supabase 연결 테스트 시작...');
|
||||
|
||||
// 결과값을 저장할 객체
|
||||
const results = {
|
||||
client: false,
|
||||
export const testSupabaseConnection = async (): Promise<TestResults> => {
|
||||
// 기본 결과 객체 초기화
|
||||
const results: TestResults = {
|
||||
url: getSupabaseUrl(),
|
||||
usingProxy: isCorsProxyEnabled(),
|
||||
proxyType: getProxyType(),
|
||||
client: true,
|
||||
restApi: false,
|
||||
auth: false,
|
||||
database: false,
|
||||
url: '', // Supabase URL
|
||||
usingProxy: false, // CORS 프록시 사용 여부
|
||||
proxyUrl: '', // 사용 중인 프록시 URL
|
||||
errors: [] as string[], // 오류 메시지 배열
|
||||
debugInfo: { // 디버깅 정보
|
||||
proxyAttempts: [] as string[],
|
||||
corsErrors: [] as string[],
|
||||
timeouts: [] as string[],
|
||||
backupProxySuccess: false
|
||||
}
|
||||
errors: []
|
||||
};
|
||||
|
||||
try {
|
||||
// 테스트 1: REST API 연결 테스트
|
||||
console.log('REST API 연결 테스트 중...');
|
||||
const apiTest = await testRestApi();
|
||||
results.restApi = apiTest.success;
|
||||
|
||||
if (!apiTest.success && apiTest.error) {
|
||||
results.errors.push(`REST API 예외: ${apiTest.error.message || '알 수 없는 오류'}`);
|
||||
// 클라이언트 유효성 체크
|
||||
if (!supabase) {
|
||||
results.client = false;
|
||||
results.errors.push('Supabase 클라이언트 초기화 실패');
|
||||
return results;
|
||||
}
|
||||
|
||||
// 테스트 2: 인증 서비스 테스트
|
||||
console.log('인증 서비스 테스트 중...');
|
||||
const authTest = await testAuthService();
|
||||
results.auth = authTest.success;
|
||||
|
||||
if (!authTest.success && authTest.error) {
|
||||
results.errors.push(`인증 오류: ${authTest.error.message || '알 수 없는 오류'}`);
|
||||
|
||||
// 테스트 실행
|
||||
const authResults = await testAuth(supabase, results.url);
|
||||
const apiResults = await testRestApi(supabase);
|
||||
const dbResults = await testDatabaseConnection(supabase);
|
||||
|
||||
// 결과 업데이트
|
||||
results.auth = authResults.success;
|
||||
results.restApi = apiResults.success;
|
||||
results.database = dbResults.success;
|
||||
|
||||
// 오류 수집
|
||||
if (!authResults.success) {
|
||||
results.errors.push(`인증 테스트 실패: ${authResults.error}`);
|
||||
}
|
||||
|
||||
// 테스트 3: 데이터베이스 테스트
|
||||
console.log('데이터베이스 테스트 중...');
|
||||
const dbTest = await testDatabase();
|
||||
results.database = dbTest.success;
|
||||
|
||||
if (!dbTest.success && dbTest.error) {
|
||||
results.errors.push(`데이터베이스 오류: ${dbTest.error.message || '알 수 없는 오류'}`);
|
||||
if (!apiResults.success) {
|
||||
results.errors.push(`REST API 테스트 실패: ${apiResults.error}`);
|
||||
}
|
||||
|
||||
// 테스트 결과 요약
|
||||
results.client = true; // 클라이언트가 초기화되었다면 여기까지 왔을 것임
|
||||
|
||||
// Supabase URL 및 프록시 정보 추가
|
||||
const supabaseUrl = (supabase as any).supabaseUrl || '';
|
||||
results.url = supabaseUrl;
|
||||
|
||||
// CORS 프록시 감지
|
||||
const isProxied = supabaseUrl.includes('corsproxy.io') ||
|
||||
supabaseUrl.includes('cors-anywhere') ||
|
||||
supabaseUrl.includes('thingproxy.freeboard.io') ||
|
||||
supabaseUrl.includes('allorigins.win');
|
||||
|
||||
results.usingProxy = isProxied;
|
||||
|
||||
if (isProxied) {
|
||||
// 프록시 URL 추출
|
||||
const proxyMatch = supabaseUrl.match(/(https?:\/\/[^\/]+\/)/);
|
||||
if (proxyMatch) {
|
||||
results.proxyUrl = proxyMatch[1];
|
||||
} else {
|
||||
results.proxyUrl = '알 수 없는 프록시';
|
||||
}
|
||||
if (!dbResults.success) {
|
||||
results.errors.push(`DB 테스트 실패: ${dbResults.error}`);
|
||||
}
|
||||
|
||||
console.log('Supabase 연결 테스트 완료:', results);
|
||||
return results;
|
||||
} catch (error: any) {
|
||||
console.error('Supabase 연결 테스트 중 예외 발생:', error);
|
||||
results.errors.push(`예상치 못한 오류: ${error.message || '알 수 없는 오류'}`);
|
||||
return results;
|
||||
results.errors.push(`테스트 실행 오류: ${error.message || '알 수 없는 오류'}`);
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user