diff --git a/app/profile-image/_components/TermsDrawer.tsx b/app/profile-image/_components/TermsDrawer.tsx index 160413f..fb71e53 100644 --- a/app/profile-image/_components/TermsDrawer.tsx +++ b/app/profile-image/_components/TermsDrawer.tsx @@ -19,27 +19,6 @@ interface TermsDrawerProps { type ViewMode = "list" | "terms" | "privacy"; -const DEFAULT_PROFILE_IDS = new Set([ - "dog", - "cat", - "dinosaur", - "otter", - "bear", - "fox", - "penguin", - "wolf", - "rabbit", - "snake", - "horse", - "frog", -]); - -const toDefaultProfileImageKey = (profileId?: string) => { - const rawId = profileId || "bear"; - if (rawId.startsWith("default_")) return rawId; - return DEFAULT_PROFILE_IDS.has(rawId) ? `default_${rawId}` : rawId; -}; - const TermsDrawer = ({ children }: TermsDrawerProps) => { const router = useRouter(); const { profile, clearProfile } = useProfile(); @@ -116,11 +95,13 @@ const TermsDrawer = ({ children }: TermsDrawerProps) => { if (!allAgreed || isSubmitting) return; try { - let finalImageUrl = toDefaultProfileImageKey(profile.profileImageUrl); + let finalImageUrl: string; // 1. 커스텀 이미지가 있으면 먼저 업로드 (Key 획득) if (profile.profileImageFile) { finalImageUrl = await uploadImage(profile.profileImageFile); + } else { + finalImageUrl = `default_${profile.profileImageUrl || "bear"}`; } // 2. 최종 데이터 객체 생성 (백엔드 양식 준수) diff --git a/hooks/useProfileSignUp.ts b/hooks/useProfileSignUp.ts index e3a27d4..2511762 100644 --- a/hooks/useProfileSignUp.ts +++ b/hooks/useProfileSignUp.ts @@ -25,17 +25,33 @@ interface SignUpResponse { * 1단계: Presigned URL을 받아오고 S3에 업로드하는 함수 */ const uploadImage = async (file: File): Promise => { - // 백엔드 명세: GET /api/members/files/presigned/profiles - const { data: response } = await api.get("/api/members/files/presigned/profiles"); + let presignedUrl: string; + let imageKey: string; - const { presignedUrl, imageKey } = response.data; + // 1단계: Presigned URL 발급 + try { + const { data: response } = await api.get( + "/api/members/files/presigned/profiles", + { params: { filename: file.name } }, + ); + presignedUrl = response.data.presignedUrl; + imageKey = response.data.imageKey; + } catch (error) { + console.error("❌ Presigned URL을 받아오지 못했습니다.", error); + throw error; + } - // S3에 직접 업로드 (Axios 인스턴스 대신 표준 axios 사용 - baseURL 무시를 위해) - await axios.put(presignedUrl, file, { - headers: { - "Content-Type": file.type, - }, - }); + // 2단계: S3에 직접 업로드 (Axios 인스턴스 대신 표준 axios 사용 - baseURL 무시를 위해) + try { + await axios.put(presignedUrl, file, { + headers: { + "Content-Type": file.type, + }, + }); + } catch (error) { + console.error("❌ 이미지 업로드에 실패했습니다.", error); + throw error; + } return imageKey; }; @@ -43,8 +59,13 @@ const uploadImage = async (file: File): Promise => { /** * 2단계: 최종 프로필 데이터를 전송하는 함수 */ -const signUpProfile = async (payload: ProfileSubmitData): Promise => { - const { data } = await api.post("/api/auth/signup/profile", payload); +const signUpProfile = async ( + payload: ProfileSubmitData, +): Promise => { + const { data } = await api.post( + "/api/auth/signup/profile", + payload, + ); return data; };