Refactor Login component
Splits the Login component into smaller, more manageable parts and extracts related logic into hooks to improve code organization and readability.
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
|
||||
// 메인 내보내기 파일
|
||||
import { supabase, isValidUrl } from './client';
|
||||
import { testSupabaseConnection } from './tests';
|
||||
|
||||
// Supabase 클라이언트 내보내기
|
||||
export { supabase } from './client';
|
||||
|
||||
// 설정 관련 유틸리티 내보내기
|
||||
export { configureSupabase } from './config';
|
||||
|
||||
// 테스트 도구 내보내기
|
||||
export { testSupabaseLogin, testSupabaseConnection } from './tests';
|
||||
export {
|
||||
supabase,
|
||||
isValidUrl,
|
||||
testSupabaseConnection
|
||||
};
|
||||
|
||||
@@ -1,96 +1,88 @@
|
||||
|
||||
import { supabase } from '../client';
|
||||
import { testAuthService } from './authTests';
|
||||
import { testRestApi } from './apiTests';
|
||||
import { testDatabaseConnection } from './databaseTests';
|
||||
import { ConnectionTestResult, TestDebugInfo } from './types';
|
||||
import { supabase } from '../client';
|
||||
import { getOriginalSupabaseUrl, getSupabaseUrl, isCorsProxyEnabled, getProxyType } from '../config';
|
||||
import { testDatabase } from './databaseTests';
|
||||
|
||||
// 기본 테스트 함수
|
||||
export const testSupabaseConnection = async (): Promise<ConnectionTestResult> => {
|
||||
// 브라우저 및 환경 정보 수집
|
||||
const browserInfo = `${navigator.userAgent}`;
|
||||
const originalUrl = getOriginalSupabaseUrl();
|
||||
const proxyUrl = getSupabaseUrl();
|
||||
const usingProxy = isCorsProxyEnabled();
|
||||
const proxyType = getProxyType();
|
||||
|
||||
// 디버그 정보 초기화
|
||||
const debugInfo: TestDebugInfo = {
|
||||
originalUrl,
|
||||
proxyUrl,
|
||||
usingProxy,
|
||||
proxyType,
|
||||
keyLength: localStorage.getItem('supabase_key')?.length || 0,
|
||||
browserInfo,
|
||||
timestamp: new Date().toISOString(),
|
||||
backupProxySuccess: false,
|
||||
lastErrorDetails: '',
|
||||
};
|
||||
|
||||
// 테스트 결과 초기화
|
||||
const result: ConnectionTestResult = {
|
||||
url: originalUrl,
|
||||
proxyUrl,
|
||||
usingProxy,
|
||||
proxyType,
|
||||
export const testSupabaseConnection = async () => {
|
||||
console.log('Supabase 연결 테스트 시작...');
|
||||
|
||||
// 결과값을 저장할 객체
|
||||
const results = {
|
||||
client: false,
|
||||
restApi: false,
|
||||
restApi: false,
|
||||
auth: false,
|
||||
database: false,
|
||||
errors: [],
|
||||
debugInfo
|
||||
url: '', // Supabase URL
|
||||
usingProxy: false, // CORS 프록시 사용 여부
|
||||
proxyUrl: '', // 사용 중인 프록시 URL
|
||||
errors: [] as string[], // 오류 메시지 배열
|
||||
debugInfo: { // 디버깅 정보
|
||||
proxyAttempts: [] as string[],
|
||||
corsErrors: [] as string[],
|
||||
timeouts: [] as string[],
|
||||
backupProxySuccess: false
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
// 클라이언트 초기화 테스트
|
||||
if (supabase) {
|
||||
result.client = true;
|
||||
} else {
|
||||
result.errors.push('Supabase 클라이언트 초기화 실패');
|
||||
}
|
||||
|
||||
// REST API 테스트
|
||||
// 테스트 1: REST API 연결 테스트
|
||||
console.log('REST API 연결 테스트 중...');
|
||||
const apiTest = await testRestApi();
|
||||
result.restApi = apiTest.success;
|
||||
results.restApi = apiTest.success;
|
||||
|
||||
if (!apiTest.success && apiTest.error) {
|
||||
result.errors.push(`REST API 오류: ${apiTest.error.message || '알 수 없는 오류'}`);
|
||||
debugInfo.lastErrorDetails = JSON.stringify(apiTest.error);
|
||||
results.errors.push(`REST API 예외: ${apiTest.error.message || '알 수 없는 오류'}`);
|
||||
}
|
||||
|
||||
// 인증 테스트
|
||||
|
||||
// 테스트 2: 인증 서비스 테스트
|
||||
console.log('인증 서비스 테스트 중...');
|
||||
const authTest = await testAuthService();
|
||||
result.auth = authTest.success;
|
||||
results.auth = authTest.success;
|
||||
|
||||
if (!authTest.success && authTest.error) {
|
||||
result.errors.push(`인증 오류: ${authTest.error.message || '알 수 없는 오류'}`);
|
||||
if (!debugInfo.lastErrorDetails) {
|
||||
debugInfo.lastErrorDetails = JSON.stringify(authTest.error);
|
||||
}
|
||||
results.errors.push(`인증 오류: ${authTest.error.message || '알 수 없는 오류'}`);
|
||||
}
|
||||
|
||||
// 데이터베이스 테스트
|
||||
const dbTest = await testDatabaseConnection();
|
||||
result.database = dbTest.success;
|
||||
|
||||
// 테스트 3: 데이터베이스 테스트
|
||||
console.log('데이터베이스 테스트 중...');
|
||||
const dbTest = await testDatabase();
|
||||
results.database = dbTest.success;
|
||||
|
||||
if (!dbTest.success && dbTest.error) {
|
||||
result.errors.push(`데이터베이스 오류: ${dbTest.error.message || '알 수 없는 오류'}`);
|
||||
if (!debugInfo.lastErrorDetails) {
|
||||
debugInfo.lastErrorDetails = JSON.stringify(dbTest.error);
|
||||
results.errors.push(`데이터베이스 오류: ${dbTest.error.message || '알 수 없는 오류'}`);
|
||||
}
|
||||
|
||||
// 테스트 결과 요약
|
||||
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 (usingProxy && !result.restApi && !result.auth && !result.database) {
|
||||
console.log('모든 테스트가 실패했습니다. 다른 프록시 테스트를 시도합니다...');
|
||||
debugInfo.backupProxySuccess = false; // 백업 프록시 테스트 결과 초기화
|
||||
}
|
||||
|
||||
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;
|
||||
} catch (error: any) {
|
||||
console.error('Supabase 연결 테스트 중 예외 발생:', error);
|
||||
results.errors.push(`예상치 못한 오류: ${error.message || '알 수 없는 오류'}`);
|
||||
return results;
|
||||
}
|
||||
};
|
||||
|
||||
export { testAuthService, testRestApi, testDatabaseConnection };
|
||||
|
||||
Reference in New Issue
Block a user