diff --git a/src/components/login/Button.tsx b/src/components/login/Button.tsx index cb2a6a7..d8aca06 100644 --- a/src/components/login/Button.tsx +++ b/src/components/login/Button.tsx @@ -1,5 +1,6 @@ /** @jsxImportSource @emotion/react */ import styled from "@emotion/styled"; +import { useNavigate } from "react-router-dom"; const ButtonStyle = styled.button` cursor: pointer; @@ -15,6 +16,12 @@ const ButtonStyle = styled.button` `; const Button = ({ handleLogin }: { handleLogin: () => void }) => { - return 로그인; + const navigate = useNavigate(); + + const onClick = () => { + handleLogin(); + navigate("/home"); // handleLogin 실행 후 네비게이트 + }; + return 로그인; }; export default Button; diff --git a/src/components/pages/JoinPage.tsx b/src/components/pages/JoinPage.tsx index aaf5f79..4765457 100644 --- a/src/components/pages/JoinPage.tsx +++ b/src/components/pages/JoinPage.tsx @@ -4,6 +4,7 @@ import styled from "@emotion/styled"; import GotoLogin from "../join/GotoLogin"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; +import { handleSignup } from "../../services/handleSignup"; const JoinContainerStyle = styled.div` display: flex; @@ -37,42 +38,7 @@ const JoinPage = () => { const [newPw, setNewPw] = useState(""); const [checkNewPw, setCheckNewPw] = useState(""); const [newAlias, setNewAlias] = useState(""); - - const handleSignup = async () => { - const navigate = useNavigate(); - if (newPw !== checkNewPw) { - alert("비밀번호가 일치하지 않습니다."); - return; - } - const signupData = { - loginId: newId, - username: newAlias, - password: newPw, - }; - - try { - const response = await fetch( - "http://13.125.208.182:8080/v1/members/join", - { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(signupData), - credentials: "include", - } - ); - if (response.ok) { - alert("회원가입에 성공했습니다!"); - navigate("/login"); - } else { - const errorData = await response.json(); - alert(`회원가입 실패: ${errorData.message}`); - console.log(`Error status : ${response.status}`); - } - } catch (error) { - console.log("회원가입 요청 중 오류 발생:", error); - alert("회원가입 요청 중 문제가 발생했습니다."); - } - }; + const navigator = useNavigate(); return ( <> @@ -89,7 +55,11 @@ const JoinPage = () => { checkNewPw={checkNewPw} setCheckNewPw={setCheckNewPw} /> -