Investigate login/register 404 errors
Investigate and address persistent 404 errors occurring during login and registration processes.
This commit is contained in:
@@ -13,7 +13,8 @@ export const signIn = async (email: string, password: string) => {
|
||||
// 서버 연결 상태 먼저 확인
|
||||
const connectionStatus = await verifyServerConnection();
|
||||
if (!connectionStatus.connected) {
|
||||
showAuthToast('서버 연결 실패', connectionStatus.message, 'destructive');
|
||||
console.log('서버 연결 실패, 오프라인 모드 활성화를 고려하세요.');
|
||||
showAuthToast('서버 연결 실패', `${connectionStatus.message} (오프라인 모드를 사용해보세요)`, 'destructive');
|
||||
return {
|
||||
error: { message: `서버 연결에 실패했습니다: ${connectionStatus.message}` },
|
||||
user: null
|
||||
@@ -33,8 +34,13 @@ export const signIn = async (email: string, password: string) => {
|
||||
showAuthToast('로그인 성공', '환영합니다!');
|
||||
return { error: null, user: data.user };
|
||||
} else if (error) {
|
||||
// JSON 파싱 오류인 경우 직접 API 호출 시도
|
||||
if (error.message.includes('json') || error.message.includes('Unexpected end')) {
|
||||
console.error('로그인 오류:', error.message);
|
||||
|
||||
// REST API 오류인 경우 직접 API 호출 시도
|
||||
if (error.message.includes('json') ||
|
||||
error.message.includes('Unexpected end') ||
|
||||
error.message.includes('404') ||
|
||||
error.message.includes('Not Found')) {
|
||||
console.warn('기본 로그인 실패, 직접 API 호출 시도:', error.message);
|
||||
return await signInWithDirectApi(email, password);
|
||||
} else {
|
||||
@@ -51,8 +57,17 @@ export const signIn = async (email: string, password: string) => {
|
||||
return { error: { message: errorMessage }, user: null };
|
||||
}
|
||||
}
|
||||
} catch (basicAuthError) {
|
||||
} catch (basicAuthError: any) {
|
||||
console.warn('기본 인증 방식 예외 발생:', basicAuthError);
|
||||
|
||||
// 404 에러나 경로 오류인 경우에도 직접 API 호출 시도
|
||||
if (basicAuthError.message && (
|
||||
basicAuthError.message.includes('404') ||
|
||||
basicAuthError.message.includes('Not Found')
|
||||
)) {
|
||||
return await signInWithDirectApi(email, password);
|
||||
}
|
||||
|
||||
// 기본 로그인 실패 시 아래 직접 API 호출 방식 계속 진행
|
||||
return await signInWithDirectApi(email, password);
|
||||
}
|
||||
@@ -64,7 +79,7 @@ export const signIn = async (email: string, password: string) => {
|
||||
|
||||
// 네트워크 오류 확인
|
||||
const errorMessage = handleNetworkError(error);
|
||||
showAuthToast('로그인 오류', errorMessage, 'destructive');
|
||||
showAuthToast('로그인 오류', `${errorMessage} (오프라인 모드를 사용해보세요)`, 'destructive');
|
||||
|
||||
return { error: { message: errorMessage }, user: null };
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
|
||||
try {
|
||||
// 로그인 API 엔드포인트 URL과 헤더 준비
|
||||
const tokenUrl = `${supabase.auth.url}/token?grant_type=password`;
|
||||
const supabaseUrl = supabase.auth.url;
|
||||
const tokenUrl = `${supabaseUrl}/auth/v1/token?grant_type=password`;
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${supabase.supabaseKey}`,
|
||||
@@ -39,7 +40,50 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
}
|
||||
|
||||
if (response.status === 404) {
|
||||
showAuthToast('로그인 실패', '서버 경로를 찾을 수 없습니다. Supabase URL을 확인하세요.', 'destructive');
|
||||
console.warn('API 경로를 찾을 수 없음 (404). 새 엔드포인트 시도 중...');
|
||||
|
||||
// 대체 엔드포인트 시도 (/token 대신 /signin)
|
||||
const signinUrl = `${supabaseUrl}/auth/v1/signin`;
|
||||
|
||||
try {
|
||||
const signinResponse = await fetch(signinUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({ email, password })
|
||||
});
|
||||
|
||||
console.log('대체 로그인 경로 응답 상태:', signinResponse.status);
|
||||
|
||||
if (signinResponse.status === 404) {
|
||||
showAuthToast('로그인 실패', '서버 설정을 확인하세요: 인증 API 경로를 찾을 수 없습니다.', 'destructive');
|
||||
return {
|
||||
error: { message: '서버 설정 문제: 인증 API 경로를 찾을 수 없습니다. Supabase URL을 확인하세요.' },
|
||||
user: null
|
||||
};
|
||||
}
|
||||
|
||||
// 대체 응답 처리
|
||||
const signinData = await parseResponse(signinResponse);
|
||||
if (signinData.error) {
|
||||
showAuthToast('로그인 실패', signinData.error, 'destructive');
|
||||
return { error: { message: signinData.error }, user: null };
|
||||
}
|
||||
|
||||
if (signinData.access_token) {
|
||||
await supabase.auth.setSession({
|
||||
access_token: signinData.access_token,
|
||||
refresh_token: signinData.refresh_token || ''
|
||||
});
|
||||
|
||||
const { data: userData } = await supabase.auth.getUser();
|
||||
showAuthToast('로그인 성공', '환영합니다!');
|
||||
return { error: null, user: userData.user };
|
||||
}
|
||||
} catch (altError) {
|
||||
console.error('대체 로그인 엔드포인트 오류:', altError);
|
||||
}
|
||||
|
||||
showAuthToast('로그인 실패', '서버 설정을 확인하세요: 인증 API 경로를 찾을 수 없습니다.', 'destructive');
|
||||
return {
|
||||
error: { message: '서버 경로를 찾을 수 없습니다. Supabase URL을 확인하세요.' },
|
||||
user: null
|
||||
@@ -81,7 +125,7 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
// 로그인 성공 시 Supabase 세션 설정
|
||||
await supabase.auth.setSession({
|
||||
access_token: responseData.access_token,
|
||||
refresh_token: responseData.refresh_token
|
||||
refresh_token: responseData.refresh_token || ''
|
||||
});
|
||||
|
||||
// 사용자 정보 가져오기
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user