From 614c7bd992d6e15352cff60b40887c95b062a28e Mon Sep 17 00:00:00 2001 From: koreacomp5 Date: Fri, 10 Oct 2025 14:25:29 +0900 Subject: [PATCH] =?UTF-8?q?=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=ED=8F=BC?= =?UTF-8?q?=20=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/register/page.tsx | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/app/register/page.tsx b/src/app/register/page.tsx index f39ab34..c9c6847 100644 --- a/src/app/register/page.tsx +++ b/src/app/register/page.tsx @@ -15,6 +15,7 @@ export default function RegisterPage() { agreeTerms: false, }); const [loading, setLoading] = React.useState(false); + const [errors, setErrors] = React.useState>({}); const onChange = (e: React.ChangeEvent) => { const { name, value, type, checked } = e.target; setForm((f) => ({ ...f, [name]: type === "checkbox" ? checked : value })); @@ -29,7 +30,13 @@ export default function RegisterPage() { body: JSON.stringify(form), }); const data = await res.json(); - if (!res.ok) throw new Error(data?.error || "회원가입 실패"); + if (!res.ok) { + const fieldErrors = (data?.error?.fieldErrors ?? {}) as Record; + setErrors(fieldErrors); + const msg = data?.error?.message || Object.values(fieldErrors)[0]?.[0] || "회원가입 실패"; + throw new Error(msg); + } + setErrors({}); show("회원가입 성공! 로그인해주세요"); location.href = "/login"; } catch (err: any) { @@ -42,12 +49,30 @@ export default function RegisterPage() {

회원가입

- - - - - - + + {errors.nickname?.length ? ( + {errors.nickname[0]} + ) : null} + + {errors.name?.length ? ( + {errors.name[0]} + ) : null} + + {errors.phone?.length ? ( + {errors.phone[0]} + ) : null} + + {errors.birth?.length ? ( + {errors.birth[0]} + ) : null} + + {errors.password?.length ? ( + {errors.password[0]} + ) : null} + + {errors.confirmPassword?.length ? ( + {errors.confirmPassword[0]} + ) : null}