Skip to content

Commit

Permalink
feat: 이메일 중복 검사 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
78-artilleryman committed Apr 7, 2024
1 parent 50a7909 commit 0939f8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pages/signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import LogoBox from "@/src/components/signinPage/LogoBox";
import { useForm } from "react-hook-form";
import SocialBox from "@/src/components/signinPage/SocialBox";
import ErrorMesage from "@/src/components/signinPage/ErrorMesage";
import { signupRequest } from "@/src/utils/Api";
import { chechEmail, signupRequest } from "@/src/utils/Api";
import { useRouter } from "next/router";

const BackGround = styled.div`
Expand Down Expand Up @@ -55,6 +55,10 @@ function SignupPage() {
value: /^\S+@\S+$/i,
message: "올바른 이메일 주소가 아닙니다.",
},
validate: async (value) => {
const res = await chechEmail(value);
if (!res) return "이미 존재하는 이메일입니다.";
},
});

const passwordValidation = register("userPw", {
Expand Down
23 changes: 23 additions & 0 deletions src/utils/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,26 @@ export async function signupRequest(formdata: FormdataType) {
return null;
}
}

export async function chechEmail(email: string) {
try {
const response = await axios.post(`${BASE_URL}check-email`, {
email: email,
});

if (response.status === 200) {
const res = response.data;
return res;
} else if (response.status === 400) {
console.log("잘 못 된 정보를 입력했습니다.");
} else if (response.status === 409) {
console.log("이메일이 중복되었습니다.");
} else if (response.status === 500) {
console.log("서버에러");
}
} catch (error) {
// 네트워크 연결 오류 처리
console.error("Network error:", error);
return null;
}
}

0 comments on commit 0939f8f

Please sign in to comment.