Investigate login/signup failure
Investigate and address the "Failed to fetch" error during signup and login failures.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
import { supabase } from '@/lib/supabase';
|
||||
import { parseResponse, showAuthToast, handleNetworkError } from '@/utils/auth';
|
||||
import { getProxyType, isCorsProxyEnabled } from '@/lib/supabase/config';
|
||||
import { getProxyType, isCorsProxyEnabled, getSupabaseUrl, getOriginalSupabaseUrl } from '@/lib/supabase/config';
|
||||
|
||||
/**
|
||||
* 직접 API 호출을 통한 로그인 시도 (대체 방법)
|
||||
@@ -11,23 +11,27 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
|
||||
try {
|
||||
// API 호출 URL 및 헤더 설정
|
||||
const supabaseUrl = localStorage.getItem('supabase_url') || 'https://a11.ism.kr';
|
||||
const supabaseUrl = getOriginalSupabaseUrl(); // 원본 URL 사용
|
||||
const proxyUrl = getSupabaseUrl(); // 프록시 적용된 URL
|
||||
const supabaseKey = localStorage.getItem('supabase_key') || supabase.supabaseKey;
|
||||
|
||||
// 프록시 정보 로그
|
||||
const usingProxy = isCorsProxyEnabled();
|
||||
const proxyType = getProxyType();
|
||||
console.log(`CORS 프록시 사용: ${usingProxy ? '예' : '아니오'}, 타입: ${proxyType}`);
|
||||
console.log(`CORS 프록시 사용: ${usingProxy ? '예' : '아니오'}, 타입: ${proxyType}, 프록시 URL: ${proxyUrl}`);
|
||||
|
||||
// 실제 요청에 사용할 URL 결정 (항상 프록시 URL 사용)
|
||||
const useUrl = usingProxy ? proxyUrl : supabaseUrl;
|
||||
|
||||
// URL에 auth/v1이 이미 포함되어있는지 확인
|
||||
const baseUrl = supabaseUrl.includes('/auth/v1') ? supabaseUrl : `${supabaseUrl}/auth/v1`;
|
||||
const baseUrl = useUrl.includes('/auth/v1') ? useUrl : `${useUrl}/auth/v1`;
|
||||
|
||||
// 토큰 엔드포인트 경로 (curl 테스트와 동일한 형식으로)
|
||||
// 토큰 엔드포인트 경로
|
||||
const tokenUrl = `${baseUrl}/token?grant_type=password`;
|
||||
|
||||
console.log('로그인 API 요청 URL:', tokenUrl);
|
||||
|
||||
// 로그인 요청 보내기 (curl 테스트와 동일한 형식으로)
|
||||
// 로그인 요청 보내기
|
||||
const response = await fetch(tokenUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
import { supabase } from '@/lib/supabase';
|
||||
import { parseResponse, showAuthToast } from '@/utils/auth';
|
||||
import { getProxyType, isCorsProxyEnabled, getSupabaseUrl, getOriginalSupabaseUrl } from '@/lib/supabase/config';
|
||||
|
||||
/**
|
||||
* 직접 API 호출을 통한 회원가입
|
||||
@@ -9,11 +10,21 @@ export const signUpWithDirectApi = async (email: string, password: string, usern
|
||||
try {
|
||||
console.log('직접 API 호출로 회원가입 시도 중');
|
||||
|
||||
const supabaseUrl = localStorage.getItem('supabase_url') || 'https://a11.ism.kr';
|
||||
// 프록시 적용된 URL과 원본 URL 모두 가져오기
|
||||
const supabaseUrl = getOriginalSupabaseUrl(); // 원본 URL
|
||||
const proxyUrl = getSupabaseUrl(); // 프록시 적용된 URL
|
||||
const supabaseKey = localStorage.getItem('supabase_key') || supabase.supabaseKey;
|
||||
|
||||
// 프록시 정보 로깅
|
||||
const usingProxy = isCorsProxyEnabled();
|
||||
const proxyType = getProxyType();
|
||||
console.log(`CORS 프록시 사용: ${usingProxy ? '예' : '아니오'}, 타입: ${proxyType}, 프록시 URL: ${proxyUrl}`);
|
||||
|
||||
// 실제 요청에 사용할 URL 결정 (항상 프록시 URL 사용)
|
||||
const useUrl = usingProxy ? proxyUrl : supabaseUrl;
|
||||
|
||||
// URL에 auth/v1이 이미 포함되어있는지 확인
|
||||
const baseUrl = supabaseUrl.includes('/auth/v1') ? supabaseUrl : `${supabaseUrl}/auth/v1`;
|
||||
const baseUrl = useUrl.includes('/auth/v1') ? useUrl : `${useUrl}/auth/v1`;
|
||||
|
||||
// 회원가입 API 엔드포인트 및 헤더 설정
|
||||
const signUpUrl = `${baseUrl}/signup`;
|
||||
@@ -125,7 +136,23 @@ export const signUpWithDirectApi = async (email: string, password: string, usern
|
||||
} catch (error: any) {
|
||||
console.error('회원가입 API 호출 중 예외 발생:', error);
|
||||
|
||||
const errorMessage = error.message || '알 수 없는 오류가 발생했습니다.';
|
||||
// 프록시 설정 확인
|
||||
const usingProxy = isCorsProxyEnabled();
|
||||
const proxyType = getProxyType();
|
||||
|
||||
// 오류 메시지 설정 및 프록시 추천
|
||||
let errorMessage = error.message || '알 수 없는 오류가 발생했습니다.';
|
||||
|
||||
if (errorMessage.includes('Failed to fetch') ||
|
||||
errorMessage.includes('NetworkError') ||
|
||||
errorMessage.includes('CORS')) {
|
||||
if (!usingProxy) {
|
||||
errorMessage += ' (설정에서 Cloudflare CORS 프록시 활성화를 권장합니다)';
|
||||
} else if (proxyType !== 'cloudflare') {
|
||||
errorMessage += ' (설정에서 Cloudflare CORS 프록시로 변경을 권장합니다)';
|
||||
}
|
||||
}
|
||||
|
||||
showAuthToast('회원가입 오류', errorMessage, 'destructive');
|
||||
|
||||
return { error: { message: errorMessage }, user: null };
|
||||
|
||||
Reference in New Issue
Block a user