diff --git a/.gitignore b/.gitignore index 362797ac983d6ad6efb5b1650aba26966c43bbc6..dbb01d8aca2e73458f79b2eb6ace2d40433a23ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules .env.development -.env \ No newline at end of file +.env +./upload \ No newline at end of file diff --git a/client/src/apis/auth.api.js b/client/src/apis/auth.api.js index 2bc5dc9a71ce363d5c2a88f81cf1014877009399..b197f88060756f32cd1ef0c2d7cb158a9e590740 100644 --- a/client/src/apis/auth.api.js +++ b/client/src/apis/auth.api.js @@ -32,13 +32,13 @@ const compareId = async (userId) => { const confirmMbnum = async (phone) => { const url = `${baseUrl}/api/auth/phone/${phone}` - const { data } = await axios.post(url) + const { data } = await axios.post(url); return data } -const confirmNum = async (num) => { - const url = `${baseUrl}/api/auth/num/${num}` - const { data } = await axios.get(url) +const confirmNum = async (confirmNum) => { + const url = `${baseUrl}/api/auth/num` + const { data } = await axios.post(url, confirmNum); return data } @@ -61,7 +61,8 @@ const comparePw = async (pw) => { const modifyUser = async (user) => { const url = `${baseUrl}/api/auth/modify` - await axios.post(url, user) + const { data } = await axios.post(url, user) + return data } const authApi = { diff --git a/client/src/components/MyInfo/MyInfo.js b/client/src/components/MyInfo/MyInfo.js index dbe435ac746266f9b64696b77375804c44d09811..29edd96b34d7b4858374a21a51600407873ec5ff 100644 --- a/client/src/components/MyInfo/MyInfo.js +++ b/client/src/components/MyInfo/MyInfo.js @@ -8,6 +8,7 @@ const MyInfo = () => { const [img, setImg] = useState(""); const [profile, setProfile] = useState(""); + const [startTime, setStartTime] = useState(""); // 사용자 이름 가져오는 함수 const getMember = async () => { const member = await authApi.getMember(); @@ -22,16 +23,21 @@ const MyInfo = () => { //변경할 데이터 입력받는 state const [userRe, setUserRe] = useState({ + userName: "", userEmail: "", userNickName: "", userMbnum: "", userPassword: "", userRePassword: "" }) + const [confirmMb, setConfirmMb] = useState(false); + const [number, setNumber] = useState(null); //각 타입별 error 유무 state + const [mbError,setMbError] = useState(false); const [error, setError] = useState(""); const [errorMsg, setErrorMsg] = useState({ + errorName: false, errorEmail: false, errorNickName: false, errorMbnum: false, @@ -62,7 +68,6 @@ const MyInfo = () => { } const enterKey = (e) => { if (e.key === "Enter") { - handleOnSummitVerify(e); } } @@ -105,6 +110,55 @@ const MyInfo = () => { } } + const handleOnClickMbnum = async (e) => { + e.preventDefault(); + try { + setStartTime(""); + setError(""); + setLoading(true); + const phone = userRe.userMbnum; + console.log("phone : ", phone); + const message = await authApi.confirmMbnum(phone); + console.log("message : ", message); + + if(message.isSuccess){ + console.log("mberror: "+mbError); + setMbError("보냄"); + setStartTime(message.startTime); + } + } catch (error) { + console.log('error'+ error) + }finally { + setLoading(false); + } + } + + const handleOnChangeMb = (e) => { + setNumber(String(e.target.value)); + } + + const handleOnClickMbConfirm = async (e) => { + e.preventDefault(); + try { + setError(""); + setLoading(true); + console.log("startTime : ", startTime); + const confirmNum = {userMbnum : userRe.userMbnum, number : number, startTime : startTime}; + console.log(confirmNum); + const message = await authApi.confirmNum(confirmNum); + console.log(message); + setMbError(message); + if(message === "성공"){ + setConfirmMb(true); + console.log("인증완료"); + } + } catch (error) { + catchErrors(error, setError); + }finally { + setLoading(false); + } + } + //비교하여 error메세지 반환 const vaildationData = (text, compareValue, error) => { if (text !== compareValue) { @@ -121,8 +175,11 @@ const MyInfo = () => { setErrorMsg(errorMsg => ({ ...errorMsg, [error]: false })); } } + //유효성 검사 const validation = () => { + //이름 유효성 검사 + vaildationData((userRe.userName.length === 0), false, "errorName"); //별명 유효성 검사 vaildationData((userRe.userNickName.length === 0), false, "errorNickName"); // 휴대폰 유효성 검사 @@ -133,31 +190,29 @@ const MyInfo = () => { vaildationData(userRe.userPassword, userRe.userRePassword, "errorRePassword"); // 최종 유효성 검사 - if ((Object.values(errorMsg).some((element) => (element)) === false)) { + if (!(Object.values(errorMsg).some((element) => (element)))) { return true } else { return false } } - - const handleOnSummit = async (e) => { e.preventDefault(); try { + console.log('handle ?????') setError(() => ("")); //처리가 될때까지 버튼(가입하기)이 안눌리게 지정 setLoading(() => (true)); - console.log("userRe : " + userRe.userEmail); //유효성 검사 let valid = validation(); - console.log("valid :" + valid); + console.log('handle on submit', valid) if (valid) { const userData = userRe; console.log(userData); //서버로 전송 - const process = await authApi.modifyUser(userData); - console.log("process : " + process); + const result = await authApi.modifyUser(userData); + console.log("result : " + result); alert("회원정보 수정 완료"); valid = false; } else { throw new Error("유효하지 않은 데이터입니다.") } @@ -190,8 +245,8 @@ const MyInfo = () => { - -