From a5d95190d991f3b7284985d068df82ccb1af512e Mon Sep 17 00:00:00 2001 From: yeon-dong Date: Wed, 28 Aug 2024 17:37:35 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[FEAT]=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FITple-Frontend/data/LoginApi.jsx | 19 +++++++++++++++++++ .../src/pages/ProfilePage/ProfilePage.jsx | 9 ++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/FITple-Frontend/data/LoginApi.jsx b/FITple-Frontend/data/LoginApi.jsx index 35e7239..db9cefc 100644 --- a/FITple-Frontend/data/LoginApi.jsx +++ b/FITple-Frontend/data/LoginApi.jsx @@ -18,6 +18,25 @@ export const login = async (loginId, loginPw) => { } }; +// 로그아웃 함수 +export const logout = async () => { + try { + const response = await fetch(`${localhost}/FITple/logout`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + }); + + if (!response.ok) { + throw new Error("로그아웃 요청에 실패했습니다."); + } + } catch (error) { + console.error("로그아웃 요청 중 오류가 발생했습니다.", error); + throw new Error("네트워크 오류가 발생했습니다. 잠시 후 다시 시도해주세요."); + } + }; export const findId = async (name, email) => { try { diff --git a/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx b/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx index 212e08c..166aa3b 100644 --- a/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx +++ b/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx @@ -18,6 +18,7 @@ import { useNavigate } from "react-router-dom"; import { getProfile } from "../../../data/GetProfileApi"; import useAuthStore from "../../../data/store/userAuthStore"; import { useEffect } from "react"; +import { logout } from "../../../data/LoginApi"; // 로그아웃 API를 가져옵니다. const ProfilePage = () => { const navigate = useNavigate(); @@ -57,6 +58,12 @@ const ProfilePage = () => { getProfileData(); }, []); + // 로그아웃 핸들러 함수 추가 +const handleLogout = async () => { + await logout(); // 로그아웃 API 호출 + navigate("/"); // "/"로 리다이렉트 +}; + return ( <> {/* 위에 box */} @@ -81,7 +88,7 @@ const ProfilePage = () => { > 문의하기 - 로그아웃 + 로그아웃 From 2c13069bbc650b1cdcb43003964219379247af9a Mon Sep 17 00:00:00 2001 From: yeon-dong Date: Thu, 29 Aug 2024 14:13:52 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[FEAT]=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx b/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx index 166aa3b..e63c42c 100644 --- a/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx +++ b/FITple-Frontend/src/pages/ProfilePage/ProfilePage.jsx @@ -59,8 +59,10 @@ const ProfilePage = () => { }, []); // 로그아웃 핸들러 함수 추가 -const handleLogout = async () => { - await logout(); // 로그아웃 API 호출 +const handleLogout = () => { + console.log("현재 토큰:", useAuthStore.getState().token); // 현재 토큰 확인 + useAuthStore.setState({ token: null }); + console.log("현재 토큰:", useAuthStore.getState().token); // 현재 토큰 확인 navigate("/"); // "/"로 리다이렉트 }; From e7a5eb8da47c7ab5cd7076b2c0bdfcb22f14d7f9 Mon Sep 17 00:00:00 2001 From: yeon-dong Date: Thu, 29 Aug 2024 14:17:29 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[FEAT]=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FITple-Frontend/data/LoginApi.jsx | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/FITple-Frontend/data/LoginApi.jsx b/FITple-Frontend/data/LoginApi.jsx index db9cefc..b1e3953 100644 --- a/FITple-Frontend/data/LoginApi.jsx +++ b/FITple-Frontend/data/LoginApi.jsx @@ -18,26 +18,6 @@ export const login = async (loginId, loginPw) => { } }; -// 로그아웃 함수 -export const logout = async () => { - try { - const response = await fetch(`${localhost}/FITple/logout`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - credentials: "include", - }); - - if (!response.ok) { - throw new Error("로그아웃 요청에 실패했습니다."); - } - } catch (error) { - console.error("로그아웃 요청 중 오류가 발생했습니다.", error); - throw new Error("네트워크 오류가 발생했습니다. 잠시 후 다시 시도해주세요."); - } - }; - export const findId = async (name, email) => { try { const response = await fetch(`${localhost}/FITple/auth/find-id`, {