The `backupProxySuccess` property was being assigned to the `debugInfo` object in the `testSupabaseConnection` function, but it was not defined in the type definition. This commit adds the `backupProxySuccess` property to the type definition of the `debugInfo` object to resolve the TypeScript error.
209 lines
7.4 KiB
TypeScript
209 lines
7.4 KiB
TypeScript
|
|
import { supabase } from './client';
|
|
import { getSupabaseUrl, getSupabaseKey, getOriginalSupabaseUrl, isCorsProxyEnabled } from './config';
|
|
|
|
// 테스트용 직접 로그인 함수 (디버깅 전용)
|
|
export const testSupabaseLogin = async (email: string, password: string) => {
|
|
try {
|
|
console.log('테스트 로그인 시도:', email);
|
|
|
|
const { data, error } = await supabase.auth.signInWithPassword({
|
|
email,
|
|
password
|
|
});
|
|
|
|
if (error) {
|
|
console.error('테스트 로그인 오류:', error);
|
|
return { success: false, error };
|
|
}
|
|
|
|
console.log('테스트 로그인 성공:', data);
|
|
return { success: true, data };
|
|
} catch (err) {
|
|
console.error('테스트 로그인 중 예외 발생:', err);
|
|
return { success: false, error: err };
|
|
}
|
|
};
|
|
|
|
// API 테스트 도우미 함수
|
|
export const testSupabaseConnection = async () => {
|
|
const originalUrl = getOriginalSupabaseUrl();
|
|
const proxyUrl = getSupabaseUrl();
|
|
const usingProxy = isCorsProxyEnabled();
|
|
const supabaseKey = getSupabaseKey();
|
|
|
|
const results = {
|
|
url: originalUrl, // 원본 URL
|
|
proxyUrl: proxyUrl, // 프록시 적용된 URL
|
|
usingProxy: usingProxy, // 프록시 사용 여부
|
|
client: !!supabase,
|
|
restApi: false,
|
|
auth: false,
|
|
database: false,
|
|
errors: [] as string[],
|
|
debugInfo: {
|
|
originalUrl,
|
|
proxyUrl,
|
|
usingProxy,
|
|
keyLength: supabaseKey.length,
|
|
browserInfo: navigator.userAgent,
|
|
timestamp: new Date().toISOString(),
|
|
backupProxySuccess: false // 타입 오류 수정: backupProxySuccess 속성 추가
|
|
}
|
|
};
|
|
|
|
console.log('연결 테스트 시작 - 설정 정보:', {
|
|
originalUrl,
|
|
proxyUrl,
|
|
usingProxy
|
|
});
|
|
|
|
try {
|
|
// 1. REST API 접근 테스트 - 다양한 URL 형식 시도
|
|
try {
|
|
console.log('REST API 테스트 시작...');
|
|
|
|
// 여러 형태의 REST API 엔드포인트 URL 구성 시도
|
|
let apiUrl = '';
|
|
let response = null;
|
|
let errorBody = '';
|
|
|
|
// 1번째 시도: 기본 URL + /rest/v1/
|
|
apiUrl = proxyUrl.endsWith('/')
|
|
? `${proxyUrl}rest/v1/`
|
|
: `${proxyUrl}/rest/v1/`;
|
|
|
|
console.log('REST API 테스트 URL (시도 1):', apiUrl);
|
|
|
|
try {
|
|
response = await fetch(apiUrl, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'apikey': supabaseKey,
|
|
},
|
|
});
|
|
|
|
if (response.ok) {
|
|
results.restApi = true;
|
|
console.log('REST API 테스트 성공 (시도 1)');
|
|
} else {
|
|
errorBody = await response.text();
|
|
console.warn(`REST API 테스트 실패 (시도 1) - 상태: ${response.status}, 오류: ${errorBody}`);
|
|
|
|
// 2번째 시도: corsproxy.io URL 직접 구성
|
|
if (usingProxy) {
|
|
const directProxyUrl = `https://corsproxy.io/?${encodeURIComponent(`${originalUrl}/rest/v1/`)}`;
|
|
console.log('REST API 테스트 URL (시도 2 - 직접 프록시):', directProxyUrl);
|
|
|
|
try {
|
|
response = await fetch(directProxyUrl, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'apikey': supabaseKey,
|
|
},
|
|
});
|
|
|
|
if (response.ok) {
|
|
results.restApi = true;
|
|
console.log('REST API 테스트 성공 (시도 2)');
|
|
} else {
|
|
const error2 = await response.text();
|
|
console.warn(`REST API 테스트 실패 (시도 2) - 상태: ${response.status}, 오류: ${error2}`);
|
|
results.errors.push(`REST API 오류(${response.status}): ${error2 || errorBody || '응답 없음'}`);
|
|
}
|
|
} catch (innerErr: any) {
|
|
console.error('REST API 테스트 시도 2 예외:', innerErr);
|
|
results.errors.push(`REST API 예외 (시도 2): ${innerErr.message || '알 수 없는 오류'}`);
|
|
}
|
|
} else {
|
|
results.errors.push(`REST API 오류(${response.status}): ${errorBody || '응답 없음'}`);
|
|
}
|
|
}
|
|
} catch (outerErr: any) {
|
|
console.error('REST API 테스트 시도 1 예외:', outerErr);
|
|
results.errors.push(`REST API 예외 (시도 1): ${outerErr.message || '알 수 없는 오류'}`);
|
|
|
|
// 백업 시도
|
|
if (usingProxy) {
|
|
try {
|
|
// 백업 프록시 시도: 다른 CORS 프록시 서비스 사용
|
|
const backupProxyUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(`${originalUrl}/rest/v1/`)}`;
|
|
console.log('REST API 테스트 URL (백업 프록시):', backupProxyUrl);
|
|
|
|
response = await fetch(backupProxyUrl, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'apikey': supabaseKey,
|
|
},
|
|
});
|
|
|
|
if (response.ok) {
|
|
results.restApi = true;
|
|
console.log('REST API 테스트 성공 (백업 프록시)');
|
|
results.debugInfo.backupProxySuccess = true;
|
|
} else {
|
|
const backupError = await response.text();
|
|
console.warn(`REST API 테스트 실패 (백업 프록시) - 상태: ${response.status}, 오류: ${backupError}`);
|
|
}
|
|
} catch (backupErr: any) {
|
|
console.error('REST API 백업 프록시 예외:', backupErr);
|
|
}
|
|
}
|
|
}
|
|
} catch (err: any) {
|
|
results.errors.push(`REST API 예외: ${err.message || '알 수 없는 오류'}`);
|
|
console.error('REST API 테스트 중 예외:', err);
|
|
}
|
|
|
|
// 2. 인증 서비스 테스트
|
|
try {
|
|
console.log('인증 서비스 테스트 시작...');
|
|
const { data, error } = await supabase.auth.getSession();
|
|
results.auth = !error;
|
|
if (error) {
|
|
results.errors.push(`인증 오류: ${error.message}`);
|
|
console.error('인증 테스트 실패:', error);
|
|
} else {
|
|
console.log('인증 테스트 성공');
|
|
}
|
|
} catch (err: any) {
|
|
results.errors.push(`인증 예외: ${err.message || '알 수 없는 오류'}`);
|
|
console.error('인증 테스트 중 예외:', err);
|
|
}
|
|
|
|
// 3. 데이터베이스 연결 테스트
|
|
try {
|
|
console.log('데이터베이스 연결 테스트 시작...');
|
|
const { data, error } = await supabase
|
|
.from('transactions')
|
|
.select('*')
|
|
.limit(1);
|
|
|
|
results.database = !error;
|
|
if (error) {
|
|
results.errors.push(`데이터베이스 오류: ${error.message}`);
|
|
console.error('데이터베이스 테스트 실패:', error);
|
|
} else {
|
|
console.log('데이터베이스 테스트 성공', data);
|
|
}
|
|
} catch (err: any) {
|
|
results.errors.push(`데이터베이스 예외: ${err.message || '알 수 없는 오류'}`);
|
|
console.error('데이터베이스 테스트 중 예외:', err);
|
|
}
|
|
|
|
// 오류가 없는 경우 메시지 추가
|
|
if (results.errors.length === 0) {
|
|
results.errors.push('모든 테스트 통과! 연결 상태가 정상입니다.');
|
|
}
|
|
} catch (err: any) {
|
|
results.errors.push(`테스트 실행 예외: ${err.message || '알 수 없는 오류'}`);
|
|
console.error('전체 테스트 실행 중 예외:', err);
|
|
}
|
|
|
|
console.log('Supabase 연결 테스트 결과:', results);
|
|
return results;
|
|
};
|