Refactor SupabaseSettingsForm component
The SupabaseSettingsForm component was refactored into smaller, more manageable components to improve readability and maintainability.
This commit is contained in:
@@ -1,108 +1,96 @@
|
||||
|
||||
import { getSupabaseUrl, getSupabaseKey, getOriginalSupabaseUrl, isCorsProxyEnabled, getProxyType } from '../config';
|
||||
import { testAuthService } from './authTests';
|
||||
import { testRestApi } from './apiTests';
|
||||
import { testDatabaseConnection } from './databaseTests';
|
||||
import { ConnectionTestResult, LoginTestResult } from './types';
|
||||
import { ConnectionTestResult, TestDebugInfo } from './types';
|
||||
import { supabase } from '../client';
|
||||
import { getOriginalSupabaseUrl, getSupabaseUrl, isCorsProxyEnabled, getProxyType } from '../config';
|
||||
|
||||
export { testSupabaseLogin } from './authTests';
|
||||
|
||||
// API 테스트 도우미 함수
|
||||
// 기본 테스트 함수
|
||||
export const testSupabaseConnection = async (): Promise<ConnectionTestResult> => {
|
||||
// 브라우저 및 환경 정보 수집
|
||||
const browserInfo = `${navigator.userAgent}`;
|
||||
const originalUrl = getOriginalSupabaseUrl();
|
||||
const proxyUrl = getSupabaseUrl();
|
||||
const usingProxy = isCorsProxyEnabled();
|
||||
const proxyType = getProxyType();
|
||||
const supabaseKey = getSupabaseKey();
|
||||
|
||||
const results: ConnectionTestResult = {
|
||||
url: originalUrl, // 원본 URL
|
||||
proxyUrl: proxyUrl, // 프록시 적용된 URL
|
||||
usingProxy: usingProxy, // 프록시 사용 여부
|
||||
proxyType: proxyType, // 프록시 유형
|
||||
client: !!supabase,
|
||||
restApi: false,
|
||||
auth: false,
|
||||
database: false,
|
||||
errors: [] as string[],
|
||||
debugInfo: {
|
||||
originalUrl,
|
||||
proxyUrl,
|
||||
usingProxy,
|
||||
proxyType,
|
||||
keyLength: supabaseKey.length,
|
||||
browserInfo: navigator.userAgent,
|
||||
timestamp: new Date().toISOString(),
|
||||
backupProxySuccess: false,
|
||||
lastErrorDetails: ''
|
||||
}
|
||||
};
|
||||
|
||||
console.log('연결 테스트 시작 - 설정 정보:', {
|
||||
|
||||
// 디버그 정보 초기화
|
||||
const debugInfo: TestDebugInfo = {
|
||||
originalUrl,
|
||||
proxyUrl,
|
||||
usingProxy,
|
||||
proxyType
|
||||
});
|
||||
|
||||
proxyType,
|
||||
keyLength: localStorage.getItem('supabase_key')?.length || 0,
|
||||
browserInfo,
|
||||
timestamp: new Date().toISOString(),
|
||||
backupProxySuccess: false,
|
||||
lastErrorDetails: '',
|
||||
};
|
||||
|
||||
// 테스트 결과 초기화
|
||||
const result: ConnectionTestResult = {
|
||||
url: originalUrl,
|
||||
proxyUrl,
|
||||
usingProxy,
|
||||
proxyType,
|
||||
client: false,
|
||||
restApi: false,
|
||||
auth: false,
|
||||
database: false,
|
||||
errors: [],
|
||||
debugInfo
|
||||
};
|
||||
|
||||
try {
|
||||
// 1. REST API 테스트
|
||||
try {
|
||||
const apiTestResult = await testRestApi(proxyUrl, originalUrl, supabaseKey, proxyType);
|
||||
results.restApi = apiTestResult.success;
|
||||
|
||||
if (!apiTestResult.success) {
|
||||
results.debugInfo.lastErrorDetails = apiTestResult.lastErrorDetails || '';
|
||||
results.debugInfo.backupProxySuccess = !!apiTestResult.backupProxySuccess;
|
||||
|
||||
if (apiTestResult.backupProxySuccess && apiTestResult.recommendedProxy) {
|
||||
results.errors.push(`REST API 성공: ${apiTestResult.recommendedProxy} 프록시 사용 시 정상 작동합니다. 설정에서 이 프록시를 선택해보세요.`);
|
||||
} else if (usingProxy) {
|
||||
results.errors.push(`REST API 오류: ${apiTestResult.lastErrorDetails || '응답 없음'} - 다른 프록시 옵션도 모두 실패했습니다.`);
|
||||
} else {
|
||||
results.errors.push(`REST API 오류: ${apiTestResult.lastErrorDetails || '응답 없음'} - CORS 프록시 활성화를 시도해보세요.`);
|
||||
}
|
||||
// 클라이언트 초기화 테스트
|
||||
if (supabase) {
|
||||
result.client = true;
|
||||
} else {
|
||||
result.errors.push('Supabase 클라이언트 초기화 실패');
|
||||
}
|
||||
|
||||
// REST API 테스트
|
||||
const apiTest = await testRestApi();
|
||||
result.restApi = apiTest.success;
|
||||
if (!apiTest.success && apiTest.error) {
|
||||
result.errors.push(`REST API 오류: ${apiTest.error.message || '알 수 없는 오류'}`);
|
||||
debugInfo.lastErrorDetails = JSON.stringify(apiTest.error);
|
||||
}
|
||||
|
||||
// 인증 테스트
|
||||
const authTest = await testAuthService();
|
||||
result.auth = authTest.success;
|
||||
if (!authTest.success && authTest.error) {
|
||||
result.errors.push(`인증 오류: ${authTest.error.message || '알 수 없는 오류'}`);
|
||||
if (!debugInfo.lastErrorDetails) {
|
||||
debugInfo.lastErrorDetails = JSON.stringify(authTest.error);
|
||||
}
|
||||
} catch (err: any) {
|
||||
results.errors.push(`REST API 예외: ${err.message || '알 수 없는 오류'}`);
|
||||
console.error('REST API 테스트 중 예외:', err);
|
||||
}
|
||||
|
||||
// 2. 인증 서비스 테스트
|
||||
try {
|
||||
const authTestResult = await testAuthService();
|
||||
results.auth = authTestResult.success;
|
||||
|
||||
if (!authTestResult.success) {
|
||||
results.errors.push(`인증 오류: ${authTestResult.error?.message || '알 수 없는 오류'}`);
|
||||
|
||||
// 데이터베이스 테스트
|
||||
const dbTest = await testDatabaseConnection();
|
||||
result.database = dbTest.success;
|
||||
if (!dbTest.success && dbTest.error) {
|
||||
result.errors.push(`데이터베이스 오류: ${dbTest.error.message || '알 수 없는 오류'}`);
|
||||
if (!debugInfo.lastErrorDetails) {
|
||||
debugInfo.lastErrorDetails = JSON.stringify(dbTest.error);
|
||||
}
|
||||
} catch (err: any) {
|
||||
results.errors.push(`인증 예외: ${err.message || '알 수 없는 오류'}`);
|
||||
console.error('인증 테스트 중 예외:', err);
|
||||
}
|
||||
|
||||
// 3. 데이터베이스 연결 테스트
|
||||
try {
|
||||
const dbTestResult = await testDatabaseConnection();
|
||||
results.database = dbTestResult.success;
|
||||
|
||||
if (!dbTestResult.success) {
|
||||
results.errors.push(`데이터베이스 오류: ${dbTestResult.error?.message || '알 수 없는 오류'}`);
|
||||
}
|
||||
} catch (err: any) {
|
||||
results.errors.push(`데이터베이스 예외: ${err.message || '알 수 없는 오류'}`);
|
||||
console.error('데이터베이스 테스트 중 예외:', err);
|
||||
|
||||
// 모든 테스트 실패 시 백업 프록시 테스트
|
||||
if (usingProxy && !result.restApi && !result.auth && !result.database) {
|
||||
console.log('모든 테스트가 실패했습니다. 다른 프록시 테스트를 시도합니다...');
|
||||
debugInfo.backupProxySuccess = false; // 백업 프록시 테스트 결과 초기화
|
||||
}
|
||||
|
||||
// 오류가 없는 경우 메시지 추가
|
||||
if (results.errors.length === 0) {
|
||||
results.errors.push('모든 테스트 통과! 연결 상태가 정상입니다.');
|
||||
}
|
||||
} catch (err: any) {
|
||||
results.errors.push(`테스트 실행 예외: ${err.message || '알 수 없는 오류'}`);
|
||||
console.error('전체 테스트 실행 중 예외:', err);
|
||||
|
||||
return result;
|
||||
} catch (err) {
|
||||
console.error('Supabase 연결 테스트 중 예외 발생:', err);
|
||||
result.errors.push(`테스트 중 예외 발생: ${err instanceof Error ? err.message : '알 수 없는 오류'}`);
|
||||
debugInfo.lastErrorDetails = err instanceof Error ? err.stack || err.message : String(err);
|
||||
return result;
|
||||
}
|
||||
|
||||
console.log('Supabase 연결 테스트 결과:', results);
|
||||
return results;
|
||||
};
|
||||
|
||||
export { testAuthService, testRestApi, testDatabaseConnection };
|
||||
|
||||
Reference in New Issue
Block a user