diff --git a/src/components/auth/RegisterHeader.tsx b/src/components/auth/RegisterHeader.tsx index 82e6485..dd29bb9 100644 --- a/src/components/auth/RegisterHeader.tsx +++ b/src/components/auth/RegisterHeader.tsx @@ -6,6 +6,7 @@ const RegisterHeader: React.FC = () => {

젤리의 적자탈출

새 계정을 만들고 재정 관리를 시작하세요

+

온프레미스 Supabase 연결 최적화 완료

); }; diff --git a/src/contexts/auth/signInUtils.ts b/src/contexts/auth/signInUtils.ts index 5765212..9eea282 100644 --- a/src/contexts/auth/signInUtils.ts +++ b/src/contexts/auth/signInUtils.ts @@ -13,7 +13,6 @@ export const signInWithDirectApi = async (email: string, password: string) => { const tokenUrl = `${supabase.auth.url}/token?grant_type=password`; const headers = { 'Content-Type': 'application/json', - 'apikey': supabase.supabaseKey, 'Authorization': `Bearer ${supabase.supabaseKey}`, 'X-Client-Info': 'supabase-js/2.x' }; diff --git a/src/contexts/auth/signUp.ts b/src/contexts/auth/signUp.ts index 68ecb84..76a242d 100644 --- a/src/contexts/auth/signUp.ts +++ b/src/contexts/auth/signUp.ts @@ -35,6 +35,7 @@ export const signUp = async (email: string, password: string, username: string) // 회원가입 시도 (기본 방식) try { + // 온프레미스 서버에 적합한 옵션 추가 const { data, error } = await supabase.auth.signUp({ email, password, @@ -42,6 +43,8 @@ export const signUp = async (email: string, password: string, username: string) data: { username, }, + // 이메일 확인 URL 생략 (온프레미스에서는 일반적으로 사용하지 않음) + emailRedirectTo: undefined }, }); diff --git a/src/lib/supabase/client.ts b/src/lib/supabase/client.ts index 75d48f2..0107038 100644 --- a/src/lib/supabase/client.ts +++ b/src/lib/supabase/client.ts @@ -28,9 +28,68 @@ try { fetch: (...args) => { // 첫 번째 인자는 URL 또는 Request 객체 const urlOrRequest = args[0]; + let url = ''; + let headers = {}; + + // URL 형식 변환 및 헤더 수정 + if (typeof urlOrRequest === 'string') { + url = urlOrRequest; + + // Storage API 엔드포인트 경로 수정 (buckets → bucket) + if (url.includes('/storage/v1/buckets')) { + url = url.replace('/storage/v1/buckets', '/storage/v1/bucket'); + console.log('Storage API 경로 수정:', url); + } + + // 두 번째 인자에서 헤더 가져오기 + if (args[1] && args[1].headers) { + headers = args[1].headers; + } + } else if (urlOrRequest instanceof Request) { + url = urlOrRequest.url; + + // Storage API 엔드포인트 경로 수정 (buckets → bucket) + if (url.includes('/storage/v1/buckets')) { + url = url.replace('/storage/v1/buckets', '/storage/v1/bucket'); + const newRequest = new Request(url, urlOrRequest); + urlOrRequest = newRequest; + console.log('Storage API Request 객체 경로 수정:', url); + } + } + + // Storage API 호출 감지 및 헤더 형식 수정 + if (url.includes('/storage/v1/')) { + console.log('Supabase Storage API 호출 감지'); + + // 두 번째 인자에서 헤더 가져오기 및 수정 + if (args[1] && args[1].headers) { + const originalHeaders = args[1].headers; + const apiKey = originalHeaders['apikey'] || originalHeaders['Apikey'] || supabaseAnonKey; + + // 새 헤더 객체 생성 + const newHeaders = new Headers(originalHeaders); + + // apikey 헤더가 있으면 삭제하고 Authorization 헤더로 교체 + if (newHeaders.has('apikey')) { + const apiKeyValue = newHeaders.get('apikey'); + newHeaders.delete('apikey'); + newHeaders.set('Authorization', `Bearer ${apiKeyValue}`); + } else if (newHeaders.has('Apikey')) { + const apiKeyValue = newHeaders.get('Apikey'); + newHeaders.delete('Apikey'); + newHeaders.set('Authorization', `Bearer ${apiKeyValue}`); + } else { + // apikey 헤더가 없지만 Storage API를 호출하는 경우 + newHeaders.set('Authorization', `Bearer ${supabaseAnonKey}`); + } + + // 수정된 헤더로 새 옵션 객체 생성 + args[1].headers = newHeaders; + console.log('Storage API 헤더 형식 수정 완료'); + } + } // URL 로깅 및 디버깅 - let url = typeof urlOrRequest === 'string' ? urlOrRequest : urlOrRequest.url; console.log('Supabase fetch 요청:', url); // 기본 fetch 호출