From eb34b5db35977d0cc1eb5e23579622396414f3c1 Mon Sep 17 00:00:00 2001 From: MOON Date: Thu, 18 Jul 2024 20:40:48 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:sparkles:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=8A=A4=ED=82=A4=EB=A7=88=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/schema/auth.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/schema/auth.ts diff --git a/src/schema/auth.ts b/src/schema/auth.ts new file mode 100644 index 00000000..5adda753 --- /dev/null +++ b/src/schema/auth.ts @@ -0,0 +1,20 @@ +import z from 'zod'; + +const PWD_VALIDATION = /^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,}$/; +export const PostSignUpRequest = z + .object({ + email: z.string().min(1, { message: '이메일은 필수 입력입니다.' }).email({ message: '이메일 형식으로 작성해 주세요.' }), + password: z + .string() + .min(1, { message: '비밀번호는 필수 입력입니다.' }) + .min(8, { message: '비밀번호는 최소 8자 이상입니다.' }) + .regex(PWD_VALIDATION, { message: '비밀번호는 숫자, 영문, 특수문자로만 가능합니다.' }), + passwordConfirmation: z.string().min(1, { message: '비밀번호 확인을 입력해주세요.' }), + nickname: z.string().min(1, { message: '닉네임은 필수 입력입니다.' }).max(20, { message: '닉네임은 최대 20자까지 가능합니다.' }), + }) + .refine((data) => data.password === data.passwordConfirmation, { + message: '비밀번호가 일치하지 않습니다.', + path: ['passwordConfirmation'], + }); + +export type PostSignUpRequestType = z.infer; From eaaf1cc1c891ad449f8dca58a73897374db79895 Mon Sep 17 00:00:00 2001 From: MOON Date: Thu, 18 Jul 2024 20:43:32 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:heavy=5Fplus=5Fsign:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90=20?= =?UTF-8?q?=EC=8A=A4=ED=82=A4=EB=A7=88=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/auth/SignUp.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/pages/auth/SignUp.tsx b/src/pages/auth/SignUp.tsx index 8d391488..45950892 100644 --- a/src/pages/auth/SignUp.tsx +++ b/src/pages/auth/SignUp.tsx @@ -1,14 +1,17 @@ import Image from 'next/image'; import Link from 'next/link'; import AuthLayout from '@/pageLayout/AuthLayout/AuthLayout'; -import z from 'zod'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { PostSignUpRequest, PostSignUpRequestType } from '@/schema/auth'; import { useForm } from 'react-hook-form'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; export default function SignUp() { - const form = useForm>({ + const form = useForm({ + resolver: zodResolver(PostSignUpRequest), + mode: 'onBlur', defaultValues: { email: '', password: '', @@ -17,13 +20,6 @@ export default function SignUp() { }, }); - const formSchema = z.object({ - email: z.string(), - password: z.string(), - passwordConfirmation: z.string(), - nickname: z.string(), - }); - return (
From dfb693ad6f94493547c4e240cfec9e1859662b79 Mon Sep 17 00:00:00 2001 From: MOON Date: Thu, 18 Jul 2024 20:55:46 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:lipstick:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EB=9C=B0=20=EB=95=8C=20=EB=9D=BC=EB=B2=A8?= =?UTF-8?q?,=20=EC=9D=B8=ED=92=8B=EB=8F=84=20=EA=B0=99=EC=9D=80=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=83=89=EA=B9=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/auth/SignUp.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/auth/SignUp.tsx b/src/pages/auth/SignUp.tsx index 45950892..b8f1c2e1 100644 --- a/src/pages/auth/SignUp.tsx +++ b/src/pages/auth/SignUp.tsx @@ -33,9 +33,9 @@ export default function SignUp() { ( + render={({ field, fieldState }) => ( - 이메일 + 이메일 @@ -47,9 +47,9 @@ export default function SignUp() { ( + render={({ field, fieldState }) => ( - 비밀번호 + 비밀번호 @@ -73,9 +73,9 @@ export default function SignUp() { ( + render={({ field, fieldState }) => ( - 닉네임 + 닉네임 From c1305fc2bde63b9470f0502bdd16651b56bff6d4 Mon Sep 17 00:00:00 2001 From: MOON Date: Thu, 18 Jul 2024 21:11:43 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:memo:=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=EC=9D=98=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/auth/SignUp.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/auth/SignUp.tsx b/src/pages/auth/SignUp.tsx index b8f1c2e1..de2931fe 100644 --- a/src/pages/auth/SignUp.tsx +++ b/src/pages/auth/SignUp.tsx @@ -84,7 +84,11 @@ export default function SignUp() { )} /> - From 91e1fff822e29863ab0fe796e732b7ab6bc935eb Mon Sep 17 00:00:00 2001 From: MOON Date: Thu, 18 Jul 2024 21:32:17 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:memo:=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=9D=B8?= =?UTF-8?q?=ED=92=8B=20=ED=85=8C=EB=91=90=EB=A6=AC=20=EC=83=89=EC=83=81=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/auth/SignUp.tsx | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/pages/auth/SignUp.tsx b/src/pages/auth/SignUp.tsx index de2931fe..66eb7629 100644 --- a/src/pages/auth/SignUp.tsx +++ b/src/pages/auth/SignUp.tsx @@ -37,7 +37,12 @@ export default function SignUp() { 이메일 - + @@ -51,7 +56,12 @@ export default function SignUp() { 비밀번호 - + @@ -60,10 +70,15 @@ export default function SignUp() { ( + render={({ field, fieldState }) => ( - + @@ -77,7 +92,12 @@ export default function SignUp() { 닉네임 - +