Fix login and registration issues
Addresses issues preventing successful login and registration.
This commit is contained in:
@@ -20,13 +20,63 @@ export const parseResponse = async (response: Response) => {
|
||||
const responseText = await response.text();
|
||||
console.log('응답 원본:', responseText);
|
||||
|
||||
// 빈 응답 또는 공백만 있는 응답 처리
|
||||
if (!responseText || responseText.trim() === '') {
|
||||
throw new Error('서버가 빈 응답을 반환했습니다');
|
||||
if (response.status === 401) {
|
||||
return { error: '인증 실패: 이메일 또는 비밀번호가 올바르지 않습니다.' };
|
||||
} else {
|
||||
throw new Error('서버가 빈 응답을 반환했습니다');
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.parse(responseText);
|
||||
try {
|
||||
return JSON.parse(responseText);
|
||||
} catch (parseError) {
|
||||
// JSON 파싱 오류 시 응답 상태에 따른 처리
|
||||
if (response.status === 401) {
|
||||
return { error: '인증 실패: 이메일 또는 비밀번호가 올바르지 않습니다.' };
|
||||
} else if (response.status === 404) {
|
||||
return { error: '서버 경로를 찾을 수 없습니다. Supabase URL을 확인하세요.' };
|
||||
} else {
|
||||
throw parseError;
|
||||
}
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error('응답 파싱 오류:', parseError);
|
||||
throw parseError;
|
||||
}
|
||||
};
|
||||
|
||||
// CORS 문제 확인
|
||||
export const hasCorsIssue = (error: any): boolean => {
|
||||
if (!error) return false;
|
||||
|
||||
const errorMessage = error.message || '';
|
||||
return (
|
||||
errorMessage.includes('Failed to fetch') ||
|
||||
errorMessage.includes('CORS') ||
|
||||
errorMessage.includes('Network') ||
|
||||
errorMessage.includes('프록시')
|
||||
);
|
||||
};
|
||||
|
||||
// 오프라인 모드 확인
|
||||
export const isOfflineMode = (): boolean => {
|
||||
return !navigator.onLine || localStorage.getItem('offline_mode') === 'true';
|
||||
};
|
||||
|
||||
// 데모 모드 사용자 생성 (오프라인 환경용)
|
||||
export const createDemoUser = (email: string, username: string) => {
|
||||
// 데모용 가상 사용자 정보
|
||||
const demoUser = {
|
||||
id: 'demo-' + Date.now(),
|
||||
email,
|
||||
user_metadata: { username },
|
||||
created_at: new Date().toISOString()
|
||||
};
|
||||
|
||||
// 로컬 스토리지에 저장
|
||||
localStorage.setItem('demo_user', JSON.stringify(demoUser));
|
||||
|
||||
return demoUser;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user