diff --git a/src/components/auth/RegisterForm.tsx b/src/components/auth/RegisterForm.tsx index 7fa0b7b..cdf32fe 100644 --- a/src/components/auth/RegisterForm.tsx +++ b/src/components/auth/RegisterForm.tsx @@ -1,4 +1,3 @@ - import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import { Label } from "@/components/ui/label"; @@ -9,7 +8,7 @@ import { useToast } from "@/hooks/useToast.wrapper"; import { verifyServerConnection } from "@/contexts/auth/auth.utils"; interface RegisterFormProps { - signUp: (email: string, password: string) => Promise<{ + signUp: (email: string, password: string, username: string) => Promise<{ error: any; user: any; }>; @@ -88,7 +87,7 @@ const RegisterForm: React.FC = ({ setIsLoading(true); try { - const { error, user } = await signUp(email, password); + const { error, user } = await signUp(email, password, username); if (error) { setRegisterError(error.message || '알 수 없는 오류가 발생했습니다.'); diff --git a/src/contexts/auth/signUp.ts b/src/contexts/auth/signUp.ts index 1fd9bc9..d5a9da9 100644 --- a/src/contexts/auth/signUp.ts +++ b/src/contexts/auth/signUp.ts @@ -3,7 +3,7 @@ import { supabase } from '@/lib/supabase'; import { showAuthToast, verifyServerConnection } from '@/utils/auth'; import { signUpWithDirectApi } from './signUpUtils'; -export const signUp = async (email: string, password: string) => { +export const signUp = async (email: string, password: string, username: string) => { try { // 서버 연결 상태 확인 const connectionStatus = await verifyServerConnection(); @@ -20,6 +20,11 @@ export const signUp = async (email: string, password: string) => { const { data, error } = await supabase.auth.signUp({ email, password, + options: { + data: { + username, // 사용자 이름을 메타데이터에 저장 + } + } }); if (error) { @@ -31,7 +36,7 @@ export const signUp = async (email: string, password: string) => { error.message.includes('404') || error.message.includes('Not Found')) { console.warn('기본 회원가입 실패, 직접 API 호출 시도:', error.message); - return await signUpWithDirectApi(email, password); + return await signUpWithDirectApi(email, password, username); } // 기타 오류 처리 @@ -83,7 +88,7 @@ export const signUp = async (email: string, password: string) => { error.message.includes('404') || error.message.includes('Not Found'))) { console.warn('직접 API 호출로 재시도:', error); - return await signUpWithDirectApi(email, password); + return await signUpWithDirectApi(email, password, username); } // 기타 예외 처리 diff --git a/src/contexts/auth/signUpUtils.ts b/src/contexts/auth/signUpUtils.ts index b4ba800..53cc640 100644 --- a/src/contexts/auth/signUpUtils.ts +++ b/src/contexts/auth/signUpUtils.ts @@ -5,7 +5,7 @@ import { parseResponse, showAuthToast } from '@/utils/auth'; /** * 직접 API 호출을 통한 회원가입 */ -export const signUpWithDirectApi = async (email: string, password: string) => { +export const signUpWithDirectApi = async (email: string, password: string, username: string) => { try { console.log('직접 API 호출로 회원가입 시도 중'); @@ -31,7 +31,11 @@ export const signUpWithDirectApi = async (email: string, password: string) => { const response = await fetch(signUpUrl, { method: 'POST', headers, - body: JSON.stringify({ email, password }) + body: JSON.stringify({ + email, + password, + data: { username } // 사용자 메타데이터에 username 추가 + }) }); console.log('회원가입 응답 상태:', response.status); @@ -64,7 +68,7 @@ export const signUpWithDirectApi = async (email: string, password: string) => { const user = { id: responseData.id, email: responseData.email, - user_metadata: responseData.user_metadata || {}, + user_metadata: responseData.user_metadata || { username }, app_metadata: responseData.app_metadata || {}, created_at: responseData.created_at, };