From 9e7cd1f074ba566f25c3eb0ba35ac4d3cf9c161d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 15 Mar 2025 15:20:26 +0000 Subject: [PATCH] Update default API URL Update the default Supabase API URL to http://a11.ism.kr. --- src/contexts/auth/signInUtils.ts | 9 +++++++-- src/contexts/auth/signUpUtils.ts | 9 +++++++-- src/utils/auth/validationUtils.ts | 26 +++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/contexts/auth/signInUtils.ts b/src/contexts/auth/signInUtils.ts index 84af432..9478d6e 100644 --- a/src/contexts/auth/signInUtils.ts +++ b/src/contexts/auth/signInUtils.ts @@ -16,7 +16,12 @@ export const signInWithDirectApi = async (email: string, password: string) => { ? supabaseUrl : `${supabaseUrl}/auth/v1`; - const tokenUrl = `${baseUrl}/token?grant_type=password`; + // URL에 중복 '/auth/v1' 경로가 있는지 확인하고 수정 + const normalizedUrl = baseUrl.includes('/auth/v1/auth/v1') + ? baseUrl.replace('/auth/v1/auth/v1', '/auth/v1') + : baseUrl; + + const tokenUrl = `${normalizedUrl}/token?grant_type=password`; const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${supabase.supabaseKey}`, @@ -48,7 +53,7 @@ export const signInWithDirectApi = async (email: string, password: string) => { console.warn('API 경로를 찾을 수 없음 (404). 새 엔드포인트 시도 중...'); // 대체 엔드포인트 시도 (/token 대신 /signin) - const signinUrl = `${baseUrl}/signin`; + const signinUrl = `${normalizedUrl}/signin`; try { const signinResponse = await fetch(signinUrl, { diff --git a/src/contexts/auth/signUpUtils.ts b/src/contexts/auth/signUpUtils.ts index 53cc640..e375079 100644 --- a/src/contexts/auth/signUpUtils.ts +++ b/src/contexts/auth/signUpUtils.ts @@ -17,15 +17,20 @@ export const signUpWithDirectApi = async (email: string, password: string, usern ? supabaseUrl : `${supabaseUrl}/auth/v1`; + // URL에 중복 '/auth/v1' 경로가 있는지 확인하고 수정 + const normalizedUrl = baseUrl.includes('/auth/v1/auth/v1') + ? baseUrl.replace('/auth/v1/auth/v1', '/auth/v1') + : baseUrl; + // 회원가입 API 엔드포인트 및 헤더 설정 - const signUpUrl = `${baseUrl}/signup`; + const signUpUrl = `${normalizedUrl}/signup`; const headers = { 'Content-Type': 'application/json', 'apikey': supabaseKey, 'X-Client-Info': 'supabase-js/2.x' }; - console.log('회원가입 API 요청:', signUpUrl); + console.log('회원가입 API 요청 URL:', signUpUrl); // 회원가입 요청 전송 const response = await fetch(signUpUrl, { diff --git a/src/utils/auth/validationUtils.ts b/src/utils/auth/validationUtils.ts index 91924c2..4ced1a2 100644 --- a/src/utils/auth/validationUtils.ts +++ b/src/utils/auth/validationUtils.ts @@ -3,11 +3,35 @@ * 서버 URL 검증 */ export const validateServerUrl = (url: string): boolean => { + if (!url || url.trim() === '') { + return false; + } + try { + // URL에 프로토콜이 없는 경우 http:// 추가 + const urlWithProtocol = url.match(/^https?:\/\//) ? url : `http://${url}`; + // URL 유효성 검사 - new URL(url); + new URL(urlWithProtocol); return true; } catch (e) { return false; } }; + +/** + * API 경로 정규화 함수 + */ +export const normalizeApiPath = (baseUrl: string, path: string): string => { + // 마지막 슬래시 제거 + const normalizedBase = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl; + // 앞 슬래시 추가 + const normalizedPath = path.startsWith('/') ? path : `/${path}`; + + // 이미 경로가 포함되어 있는지 확인하고 중복 방지 + if (normalizedBase.endsWith(normalizedPath)) { + return normalizedBase; + } + + return `${normalizedBase}${normalizedPath}`; +};