Add API test for login

This commit adds an API test to check if the login is working correctly.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 12:06:05 +00:00
parent 2f3dda3ca6
commit 5371462b49
2 changed files with 206 additions and 3 deletions

View File

@@ -43,14 +43,55 @@ try {
},
});
// CORS 문제 확인을 위한 기본 헤더 테스트
(async () => {
try {
// 기본 서버 상태 확인 (CORS 테스트)
console.log('Supabase 서버 상태 확인 중...');
const response = await fetch(`${supabaseUrl}/rest/v1/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'apikey': supabaseAnonKey,
},
});
if (response.ok) {
console.log('Supabase REST API 연결 성공:', response.status);
} else {
console.warn('Supabase REST API 연결 실패:', response.status);
}
} catch (err) {
console.error('Supabase 서버 상태 확인 중 오류 (CORS 문제 가능성):', err);
}
})();
// Supabase 연결 테스트
(async () => {
try {
console.log('Supabase 인증 테스트 시도 중...');
const { data, error } = await supabaseClient.auth.getSession();
if (error) {
console.warn('Supabase 연결 테스트 실패:', error.message);
} else {
console.log('Supabase 연결 성공!');
console.log('Supabase 연결 성공!', data);
}
// 추가 테스트: 공개 데이터 조회 시도
try {
console.log('Supabase 데이터베이스 공개 테이블 조회 시도...');
const { data: tableData, error: tableError } = await supabaseClient
.from('transactions')
.select('*')
.limit(1);
if (tableError) {
console.warn('Supabase 데이터베이스 테스트 실패:', tableError.message);
} else {
console.log('Supabase 데이터베이스 테스트 성공:', tableData);
}
} catch (dbErr) {
console.error('Supabase 데이터베이스 테스트 중 예외 발생:', dbErr);
}
} catch (err) {
console.error('Supabase 연결 확인 중 오류:', err);
@@ -96,3 +137,89 @@ export const configureSupabase = (url: string, key: string) => {
// 페이지 새로고침 - 새로운 설정으로 Supabase 클라이언트 초기화
window.location.reload();
};
// 테스트용 직접 로그인 함수 (디버깅 전용)
export const testSupabaseLogin = async (email: string, password: string) => {
try {
console.log('테스트 로그인 시도:', email);
const { data, error } = await supabaseClient.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 results = {
url: supabaseUrl,
client: !!supabaseClient,
restApi: false,
auth: false,
database: false,
errors: [] as string[]
};
try {
// 1. REST API 접근 테스트
try {
const response = await fetch(`${supabaseUrl}/rest/v1/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'apikey': supabaseAnonKey,
},
});
results.restApi = response.ok;
if (!response.ok) {
results.errors.push(`REST API 오류: ${response.status} ${response.statusText}`);
}
} catch (err: any) {
results.errors.push(`REST API 예외: ${err.message}`);
}
// 2. 인증 서비스 테스트
try {
const { data, error } = await supabaseClient.auth.getSession();
results.auth = !error;
if (error) {
results.errors.push(`인증 오류: ${error.message}`);
}
} catch (err: any) {
results.errors.push(`인증 예외: ${err.message}`);
}
// 3. 데이터베이스 연결 테스트
try {
const { data, error } = await supabaseClient
.from('transactions')
.select('*')
.limit(1);
results.database = !error;
if (error) {
results.errors.push(`데이터베이스 오류: ${error.message}`);
}
} catch (err: any) {
results.errors.push(`데이터베이스 예외: ${err.message}`);
}
} catch (err: any) {
results.errors.push(`테스트 실행 예외: ${err.message}`);
}
console.log('Supabase 연결 테스트 결과:', results);
return results;
};