Investigate login/register 404 errors

Investigate and address persistent 404 errors occurring during login and registration processes.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 15:01:48 +00:00
parent a32eb26105
commit e52ca26cef
7 changed files with 223 additions and 75 deletions

View File

@@ -2,7 +2,8 @@
import { supabase } from '@/lib/supabase';
import {
handleNetworkError,
showAuthToast
showAuthToast,
verifyServerConnection
} from '@/utils/auth';
import { signUpWithDirectApi } from './signUpUtils';
@@ -11,30 +12,16 @@ export const signUp = async (email: string, password: string, username: string)
console.log('회원가입 시도:', { email, username });
// 서버 연결 상태 확인
try {
const response = await fetch(`${supabase.auth.url}/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
// 연결 확인만을 위한 요청이므로 짧은 타임아웃 설정
signal: AbortSignal.timeout(5000)
});
if (!response.ok && response.status !== 401) {
// 401은 인증 필요 오류로, API 엔드포인트가 존재한다는 의미이므로 정상으로 간주
console.warn('서버 연결 확인 실패:', response.status, response.statusText);
showAuthToast('서버 연결 오류', `서버가 응답하지 않거나 오류 상태입니다 (${response.status}). 관리자에게 문의하세요.`, 'destructive');
return { error: { message: `서버 연결 오류 (${response.status})` }, user: null };
}
} catch (connectionError: any) {
console.error('서버 연결 확인 중 오류:', connectionError);
showAuthToast('서버 연결 실패', '서버에 연결할 수 없습니다. 네트워크 상태 또는 서버 주소를 확인하세요.', 'destructive');
return { error: connectionError, user: null };
const connectionStatus = await verifyServerConnection();
if (!connectionStatus.connected) {
console.warn('서버 연결 확인 실패:', connectionStatus.message);
showAuthToast('서버 연결 오류', `서버가 응답하지 않거나 오류 상태입니다: ${connectionStatus.message}. 오프라인 모드를 사용해보세요.`, 'destructive');
return { error: { message: `서버 연결 오류: ${connectionStatus.message}` }, user: null };
}
// 회원가입 시도 (기본 방식)
try {
console.log('Supabase URL:', supabase.auth.url);
// 온프레미스 서버에 적합한 옵션 추가
const { data, error } = await supabase.auth.signUp({
email,
@@ -51,6 +38,17 @@ export const signUp = async (email: string, password: string, username: string)
if (error) {
console.error('회원가입 오류:', error);
// 서버 응답 오류 (404 등)인 경우 직접 API 호출
if (error.message && (
error.message.includes('404') ||
error.message.includes('Not Found') ||
error.message.includes('json') ||
error.message.includes('Unexpected')
)) {
console.log('서버 응답 오류로 인해 직접 API 호출 시도');
return await signUpWithDirectApi(email, password, username);
}
// 사용자 친화적인 오류 메시지 설정
let errorMessage = error.message;
@@ -62,11 +60,6 @@ export const signUp = async (email: string, password: string, username: string)
errorMessage = '유효하지 않은 이메일 형식입니다.';
} else if (error.message.includes('Unable to validate')) {
errorMessage = '서버 연결 문제: 이메일 검증에 실패했습니다.';
} else if (error.message.includes('json')) {
errorMessage = '서버 응답 형식 오류: 올바른 JSON 응답이 없습니다. 직접 API 호출을 시도합니다.';
// JSON 파싱 오류 발생 시 직접 API 호출 시도
return await signUpWithDirectApi(email, password, username);
} else if (error.message.includes('fetch failed')) {
errorMessage = '서버 연결에 실패했습니다. 네트워크 연결 또는 서버 상태를 확인하세요.';
} else if (error.message.includes('Failed to fetch')) {
@@ -90,11 +83,14 @@ export const signUp = async (email: string, password: string, username: string)
} catch (signUpError: any) {
console.error('기본 회원가입 방식 실패:', signUpError);
// JSON 파싱 오류 또는 기타 예외 시 직접 API 호출 시도
// 404 응답이나 API 오류 시 직접 API 호출
if (signUpError.message && (
signUpError.message.includes('json') ||
signUpError.message.includes('Unexpected end')
signUpError.message.includes('Unexpected end') ||
signUpError.message.includes('404') ||
signUpError.message.includes('Not Found')
)) {
console.log('예외 발생으로 직접 API 호출 시도');
return await signUpWithDirectApi(email, password, username);
}
@@ -107,7 +103,7 @@ export const signUp = async (email: string, password: string, username: string)
// 네트워크 오류 확인
const errorMessage = handleNetworkError(error);
showAuthToast('회원가입 오류', errorMessage, 'destructive');
showAuthToast('회원가입 오류', `${errorMessage} (오프라인 모드를 시도해보세요)`, 'destructive');
return { error, user: null };
}
};