Remove offline mode
The offline mode was removed to focus on resolving connection issues instead of providing a workaround.
This commit is contained in:
@@ -1,109 +1,98 @@
|
||||
|
||||
import { supabase } from '@/lib/supabase';
|
||||
import {
|
||||
handleNetworkError,
|
||||
showAuthToast,
|
||||
verifyServerConnection
|
||||
} from '@/utils/auth';
|
||||
import { showAuthToast, verifyServerConnection } from '@/utils/auth';
|
||||
import { signUpWithDirectApi } from './signUpUtils';
|
||||
|
||||
export const signUp = async (email: string, password: string, username: string) => {
|
||||
export const signUp = async (email: string, password: string) => {
|
||||
try {
|
||||
console.log('회원가입 시도:', { email, username });
|
||||
|
||||
// 서버 연결 상태 확인
|
||||
const connectionStatus = await verifyServerConnection();
|
||||
if (!connectionStatus.connected) {
|
||||
console.warn('서버 연결 확인 실패:', connectionStatus.message);
|
||||
showAuthToast('서버 연결 오류', `서버가 응답하지 않거나 오류 상태입니다: ${connectionStatus.message}. 오프라인 모드를 사용해보세요.`, 'destructive');
|
||||
return { error: { message: `서버 연결 오류: ${connectionStatus.message}` }, user: null };
|
||||
console.error('서버 연결 실패:', connectionStatus.message);
|
||||
showAuthToast('회원가입 오류', `서버 연결 실패: ${connectionStatus.message}`, 'destructive');
|
||||
return { error: { message: connectionStatus.message }, user: null };
|
||||
}
|
||||
|
||||
// 회원가입 시도 (기본 방식)
|
||||
console.log('회원가입 시도:', email);
|
||||
|
||||
// 기본 회원가입 시도
|
||||
try {
|
||||
console.log('Supabase URL:', supabase.auth.url);
|
||||
// 온프레미스 서버에 적합한 옵션 추가
|
||||
const { data, error } = await supabase.auth.signUp({
|
||||
email,
|
||||
password,
|
||||
options: {
|
||||
data: {
|
||||
username,
|
||||
},
|
||||
// 이메일 확인 URL 생략 (온프레미스에서는 일반적으로 사용하지 않음)
|
||||
emailRedirectTo: undefined
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (error) {
|
||||
console.error('회원가입 오류:', error);
|
||||
|
||||
// 서버 응답 오류 (404 등)인 경우 직접 API 호출
|
||||
if (error.message && (
|
||||
// REST API 오류인 경우 직접 API 호출 시도
|
||||
if (error.message.includes('json') ||
|
||||
error.message.includes('Unexpected end') ||
|
||||
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);
|
||||
error.message.includes('Not Found')) {
|
||||
console.warn('기본 회원가입 실패, 직접 API 호출 시도:', error.message);
|
||||
return await signUpWithDirectApi(email, password);
|
||||
}
|
||||
|
||||
// 사용자 친화적인 오류 메시지 설정
|
||||
// 기타 오류 처리
|
||||
let errorMessage = error.message;
|
||||
|
||||
if (error.message.includes('User already registered')) {
|
||||
errorMessage = '이미 등록된 이메일입니다. 로그인을 시도하세요.';
|
||||
} else if (error.message.includes('Password should be at least')) {
|
||||
errorMessage = '비밀번호는 최소 6자 이상이어야 합니다.';
|
||||
} else if (error.message.includes('Invalid email')) {
|
||||
errorMessage = '유효하지 않은 이메일 형식입니다.';
|
||||
} else if (error.message.includes('Unable to validate')) {
|
||||
errorMessage = '서버 연결 문제: 이메일 검증에 실패했습니다.';
|
||||
} else if (error.message.includes('fetch failed')) {
|
||||
errorMessage = '서버 연결에 실패했습니다. 네트워크 연결 또는 서버 상태를 확인하세요.';
|
||||
} else if (error.message.includes('Failed to fetch')) {
|
||||
errorMessage = 'CORS 오류가 발생했습니다. 서버 설정을 확인하거나 네트워크 관리자에게 문의하세요.';
|
||||
errorMessage = '이미 등록된 사용자입니다.';
|
||||
} else if (error.message.includes('Signup not allowed')) {
|
||||
errorMessage = '회원가입이 허용되지 않습니다.';
|
||||
} else if (error.message.includes('Email link invalid')) {
|
||||
errorMessage = '이메일 링크가 유효하지 않습니다.';
|
||||
}
|
||||
|
||||
showAuthToast('회원가입 실패', errorMessage, 'destructive');
|
||||
return { error, user: null };
|
||||
}
|
||||
|
||||
// 성공 메시지 표시
|
||||
showAuthToast('회원가입 성공', '이메일 확인 후 로그인해주세요.');
|
||||
|
||||
// 개발 환경 또는 데모 모드에서는 즉시 로그인 허용
|
||||
if (import.meta.env.DEV || process.env.NODE_ENV === 'development') {
|
||||
// 개발 환경에서는 즉시 로그인 상태로 전환
|
||||
showAuthToast('개발 모드', '개발 환경에서는 이메일 확인 없이 로그인됩니다.');
|
||||
return { error: { message: errorMessage }, user: null };
|
||||
}
|
||||
|
||||
return { error: null, user: data.user };
|
||||
} catch (signUpError: any) {
|
||||
console.error('기본 회원가입 방식 실패:', signUpError);
|
||||
|
||||
// 404 응답이나 API 오류 시 직접 API 호출
|
||||
if (signUpError.message && (
|
||||
signUpError.message.includes('json') ||
|
||||
signUpError.message.includes('Unexpected end') ||
|
||||
signUpError.message.includes('404') ||
|
||||
signUpError.message.includes('Not Found')
|
||||
)) {
|
||||
console.log('예외 발생으로 직접 API 호출 시도');
|
||||
return await signUpWithDirectApi(email, password, username);
|
||||
// 회원가입 성공
|
||||
if (data && data.user) {
|
||||
const isEmailConfirmationRequired = data.user.identities &&
|
||||
data.user.identities.length > 0 &&
|
||||
!data.user.identities[0].identity_data?.email_verified;
|
||||
|
||||
if (isEmailConfirmationRequired) {
|
||||
showAuthToast('회원가입 성공', '이메일 인증을 완료해주세요.', 'default');
|
||||
return {
|
||||
error: null,
|
||||
user: data.user,
|
||||
message: '이메일 인증 필요',
|
||||
emailConfirmationRequired: true
|
||||
};
|
||||
} else {
|
||||
showAuthToast('회원가입 성공', '환영합니다!', 'default');
|
||||
return { error: null, user: data.user };
|
||||
}
|
||||
}
|
||||
|
||||
// 그 외 오류는 그대로 던짐
|
||||
throw signUpError;
|
||||
// 사용자 데이터가 없는 경우 (드물게 발생)
|
||||
console.warn('회원가입 응답은 성공했지만 사용자 데이터가 없습니다');
|
||||
showAuthToast('회원가입 문제', '계정이 생성되었으나 응답에 사용자 정보가 없습니다.', 'destructive');
|
||||
return { error: { message: '회원가입 완료 처리 중 문제가 발생했습니다.' }, user: null };
|
||||
} catch (error: any) {
|
||||
console.error('기본 회원가입 프로세스 예외:', error);
|
||||
|
||||
// 직접 API 호출로 대체 시도
|
||||
if (error.message && (
|
||||
error.message.includes('json') ||
|
||||
error.message.includes('fetch') ||
|
||||
error.message.includes('404') ||
|
||||
error.message.includes('Not Found'))) {
|
||||
console.warn('직접 API 호출로 재시도:', error);
|
||||
return await signUpWithDirectApi(email, password);
|
||||
}
|
||||
|
||||
// 기타 예외 처리
|
||||
showAuthToast('회원가입 예외', error.message || '알 수 없는 오류', 'destructive');
|
||||
return { error: { message: error.message || '알 수 없는 오류' }, user: null };
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('회원가입 중 예외 발생:', error);
|
||||
|
||||
// 네트워크 오류 확인
|
||||
const errorMessage = handleNetworkError(error);
|
||||
|
||||
showAuthToast('회원가입 오류', `${errorMessage} (오프라인 모드를 시도해보세요)`, 'destructive');
|
||||
return { error, user: null };
|
||||
console.error('회원가입 전역 예외:', error);
|
||||
showAuthToast('회원가입 오류', error.message || '알 수 없는 오류', 'destructive');
|
||||
return { error: { message: error.message || '알 수 없는 오류' }, user: null };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user