From 37e5507fd2d3a6cbb208583ed4b97c8684cb6bc8 Mon Sep 17 00:00:00 2001 From: "using6843@gmail.com" Date: Wed, 4 Dec 2024 17:57:49 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85?= =?UTF-8?q?=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EC=B2=B4=ED=81=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Intro/SignUpModal.tsx | 17 ++++++++++--- apps/frontend/src/services/AuthApi.tsx | 25 +++++++++++++++++++ apps/frontend/src/services/LotteryApi.tsx | 3 +++ apps/frontend/src/services/MailApi.tsx | 6 +++++ apps/frontend/src/services/RankApi.tsx | 4 +++ 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/apps/frontend/src/components/Intro/SignUpModal.tsx b/apps/frontend/src/components/Intro/SignUpModal.tsx index de29cf2..ec264a8 100644 --- a/apps/frontend/src/components/Intro/SignUpModal.tsx +++ b/apps/frontend/src/components/Intro/SignUpModal.tsx @@ -1,7 +1,7 @@ import { useState, useRef, useContext, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { ModalStep } from '@/constants/ModalConstants'; -import { signUp, login } from '@/services/AuthApi'; +import { signUp, login, dupAccount } from '@/services/AuthApi'; import { AlertContext } from '@/components/public/AlertContext'; interface SignUpModalProps { @@ -23,7 +23,7 @@ const SignUpModal: React.FC = ({ step, setModalStep }) => { const pwCheckInputRef = useRef(null); const idInputRef = useRef(null); - const handleSign1 = () => { + const handleSign1 = async () => { const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; if (!email || !emailRegex.test(email)) { setError('유효한 이메일을 입력해주세요.'); @@ -43,8 +43,17 @@ const SignUpModal: React.FC = ({ step, setModalStep }) => { return; } - setError(null); - setModalStep(ModalStep.SignUpStep2); + try { + const dupCheck = await dupAccount(email); + if (dupCheck.success) { + setError(null); + setModalStep(ModalStep.SignUpStep2); + } else { + setError(dupCheck.message); + } + } catch { + setError('회원가입 중 오류가 발생했습니다. 다시 시도해주세요.'); + } }; const handleSign2 = async () => { diff --git a/apps/frontend/src/services/AuthApi.tsx b/apps/frontend/src/services/AuthApi.tsx index 7c65b2a..260c6a9 100644 --- a/apps/frontend/src/services/AuthApi.tsx +++ b/apps/frontend/src/services/AuthApi.tsx @@ -17,6 +17,8 @@ export const login = async (data: Login) => { message: response.data.message, nickname: nickname }; + } else if (response.data.code === 400 || response.data.code === 401) { + return { success: false, message: response.data.message }; } return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; @@ -25,12 +27,28 @@ export const login = async (data: Login) => { } }; +export const dupAccount = async (email: string) => { + try { + const response = await api.post('auth/emailcheck', { email }); + + if (response.data.code === 200) { + return { success: true, message: response.data.message }; + } + + return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; + } catch (error) { + return handleError(error, '회원가입 중 오류가 발생했습니다.'); + } +}; + export const signUp = async (data: SignUp) => { try { const response = await api.post('auth/signup', data); if (response.data.code === 201) { return { success: true, message: response.data.message }; + } else if (response.data.code === 400) { + return { success: false, message: response.data.message }; } return { success: false, message: response.data.message }; @@ -49,6 +67,8 @@ export const logout = async () => { localStorage.removeItem('nickname'); return { success: true, message: response.data.message }; + } else if (response.data.code === 401) { + return { success: false, message: response.data.message }; } return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; @@ -83,7 +103,10 @@ export const updateNickname = async (data: Nickname) => { if (response.data.code === 200) { return { success: true, message: response.data.message }; + } else if (response.data.code === 400 || response.data.code === 401) { + return { success: false, message: response.data.message }; } + return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; } catch (error) { return handleError(error, '닉네임 변경 중 오류가 발생했습니다.'); @@ -96,6 +119,8 @@ export const updateIntroduce = async (data: Introduce) => { if (response.data.code === 200) { return { success: true, message: response.data.message }; + } else if (response.data.code === 401) { + return { success: false, message: response.data.message }; } return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; diff --git a/apps/frontend/src/services/LotteryApi.tsx b/apps/frontend/src/services/LotteryApi.tsx index 205eed1..a33d884 100644 --- a/apps/frontend/src/services/LotteryApi.tsx +++ b/apps/frontend/src/services/LotteryApi.tsx @@ -14,7 +14,10 @@ export const getLottoResult = async () => { remainCash: remainCash, rank: rank }; + } else if (response.data.code === 400) { + return { success: false, message: response.data.message }; } + return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; } catch (error) { return handleError(error, '데이터 로딩 중 오류가 발생했습니다.'); diff --git a/apps/frontend/src/services/MailApi.tsx b/apps/frontend/src/services/MailApi.tsx index f0bc7c8..3284cef 100644 --- a/apps/frontend/src/services/MailApi.tsx +++ b/apps/frontend/src/services/MailApi.tsx @@ -13,7 +13,10 @@ export const getAlarm = async () => { message: response.data.message, alarm: alarm }; + } else if (response.data.code === 400) { + return { success: false, message: response.data.message }; } + return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; } catch (error) { return handleError(error, '데이터 로딩 중 오류가 발생했습니다.'); @@ -26,7 +29,10 @@ export const clearAlarm = async () => { if (response.data.code === 200) { return { success: true, message: response.data.message }; + } else if (response.data.code === 400) { + return { success: false, message: response.data.message }; } + return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; } catch (error) { return handleError(error, '데이터 로딩 중 오류가 발생했습니다.'); diff --git a/apps/frontend/src/services/RankApi.tsx b/apps/frontend/src/services/RankApi.tsx index 0449ebd..cd2833e 100644 --- a/apps/frontend/src/services/RankApi.tsx +++ b/apps/frontend/src/services/RankApi.tsx @@ -13,6 +13,8 @@ export const getTop5 = async () => { message: response.data.message, top5: top5 }; + } else if (response.data.code === 401) { + return { success: false, message: response.data.message }; } return { success: false, message: '알 수 없는 오류가 발생했습니다.' }; @@ -34,6 +36,8 @@ export const getMyRank = async () => { rank: rank, percentage: percentage }; + } else if (response.data.code === 401) { + return { success: false, message: response.data.message }; } return { success: false, message: '알 수 없는 오류가 발생했습니다.' };