Investigate Supabase connection issues
Investigate REST API and database connection failures despite successful authentication.
This commit is contained in:
@@ -27,43 +27,130 @@ export const testSupabaseLogin = async (email: string, password: string) => {
|
||||
|
||||
// API 테스트 도우미 함수
|
||||
export const testSupabaseConnection = async () => {
|
||||
const originalUrl = getOriginalSupabaseUrl();
|
||||
const proxyUrl = getSupabaseUrl();
|
||||
const usingProxy = isCorsProxyEnabled();
|
||||
const supabaseKey = getSupabaseKey();
|
||||
|
||||
const results = {
|
||||
url: getOriginalSupabaseUrl(), // 원본 URL
|
||||
proxyUrl: getSupabaseUrl(), // 프록시 적용된 URL
|
||||
usingProxy: isCorsProxyEnabled(), // 프록시 사용 여부
|
||||
url: originalUrl, // 원본 URL
|
||||
proxyUrl: proxyUrl, // 프록시 적용된 URL
|
||||
usingProxy: usingProxy, // 프록시 사용 여부
|
||||
client: !!supabase,
|
||||
restApi: false,
|
||||
auth: false,
|
||||
database: false,
|
||||
errors: [] as string[]
|
||||
errors: [] as string[],
|
||||
debugInfo: {
|
||||
originalUrl,
|
||||
proxyUrl,
|
||||
usingProxy,
|
||||
keyLength: supabaseKey.length,
|
||||
browserInfo: navigator.userAgent,
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
};
|
||||
|
||||
console.log('연결 테스트 시작 - 설정 정보:', {
|
||||
originalUrl,
|
||||
proxyUrl,
|
||||
usingProxy
|
||||
});
|
||||
|
||||
try {
|
||||
// 1. REST API 접근 테스트
|
||||
// 1. REST API 접근 테스트 - 다양한 URL 형식 시도
|
||||
try {
|
||||
console.log('REST API 테스트 시작...');
|
||||
// 정확한 REST API 엔드포인트 구성
|
||||
const apiUrl = results.proxyUrl.endsWith('/')
|
||||
? `${results.proxyUrl}rest/v1/`
|
||||
: `${results.proxyUrl}/rest/v1/`;
|
||||
|
||||
console.log('REST API 테스트 URL:', apiUrl);
|
||||
// 여러 형태의 REST API 엔드포인트 URL 구성 시도
|
||||
let apiUrl = '';
|
||||
let response = null;
|
||||
let errorBody = '';
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'apikey': getSupabaseKey(),
|
||||
},
|
||||
});
|
||||
// 1번째 시도: 기본 URL + /rest/v1/
|
||||
apiUrl = proxyUrl.endsWith('/')
|
||||
? `${proxyUrl}rest/v1/`
|
||||
: `${proxyUrl}/rest/v1/`;
|
||||
|
||||
results.restApi = response.ok;
|
||||
if (!response.ok) {
|
||||
const errorBody = await response.text();
|
||||
results.errors.push(`REST API 오류(${response.status} ${response.statusText}): ${errorBody || '응답 없음'}`);
|
||||
console.error('REST API 테스트 실패:', response.status, errorBody);
|
||||
} else {
|
||||
console.log('REST API 테스트 성공');
|
||||
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 || '알 수 없는 오류'}`);
|
||||
|
||||
Reference in New Issue
Block a user