From d3a1d2752b39389148c28dc2cf03bc5917134414 Mon Sep 17 00:00:00 2001 From: "SK\\ssssk" Date: Mon, 30 Sep 2024 21:52:36 +0900 Subject: [PATCH 01/16] =?UTF-8?q?fix:=20=EC=9C=A0=EC=A0=80=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EA=B0=80=20'=EB=8C=80=EA=B8=B0'=EC=9D=B8=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=EB=8A=94=20=EC=BF=A0=ED=82=A4=EB=A5=BC=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=95=84=EC=9B=83=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/containers/common/HeaderContainer.tsx | 49 +++++++++++------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/containers/common/HeaderContainer.tsx b/src/containers/common/HeaderContainer.tsx index 8257bf5b..20073a69 100644 --- a/src/containers/common/HeaderContainer.tsx +++ b/src/containers/common/HeaderContainer.tsx @@ -1,17 +1,19 @@ "use client"; import Header from "@/components/common/Header"; +import useModalState from "@/hooks/useModalState"; +import useOutsideClick from "@/hooks/useOutsideClick"; +import usePreventBodyScroll from "@/hooks/usePreventBodyScroll"; import useAuthStore from "@/store/authStore"; import { fetchWithAuth } from "@/utils/fetchWithAuth"; import { usePathname, useRouter } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; const HeaderContainer = () => { const pathname = usePathname(); const [visible, setVisible] = useState(false); const [transparent, setTransparent] = useState(true); const authStore = useAuthStore(); - const router = useRouter(); const onScroll = () => { if (window.scrollY >= 500) { @@ -29,19 +31,7 @@ const HeaderContainer = () => { setVisible(false); }; - const logoutHandler = async () => { - // api로 로그아웃 요청해서 쿠키제거 - const response = await fetch("/api/auth/logout", { - method: "POST", - }); - if (!response.ok) { - throw new Error(response.statusText); - } - authStore.initialize(); - router.push("/"); - router.refresh(); - }; useEffect(() => { // 모달창이 열린 상태로 새로고침을 하게되는 경우 히스토리 스택을 제거하기 위해서 뒤로가기 실행 @@ -59,16 +49,26 @@ const HeaderContainer = () => { // 자동 로그인 const login = async () => { try { - const data = await fetchWithAuth("/api/auth/user"); - if (data.status == 200) { - data.json().then((res) => { - authStore.setUser(res); - }); - } else { - authStore.setUser({ - id: -1, - }); + const res = await fetchWithAuth("/api/auth/user"); + if (res.status == 200) { + const data = await res.json(); + // 유저 상태가 '대기'인 경우는 쿠키를 제거하기 위해 로그아웃 처리 + if (data.userStatus == "대기") { + await fetchWithAuth("/api/auth/logout", { + method: "POST" + }); + authStore.setUser({ + id: -1, + }); + } + else { + authStore.setUser(data); + } + return; } + authStore.setUser({ + id: -1, + }); } catch { authStore.setUser({ id: -1, @@ -87,9 +87,6 @@ const HeaderContainer = () => { onMenuClicked={onMenuClicked} onClose={onClose} userId={authStore.id} - userSex={authStore.sex} - userProfile={authStore.userImage.address} - logoutHandler={logoutHandler} /> ); }; From dbbde25d2514737cb083d70224d1eb8498fd807c Mon Sep 17 00:00:00 2001 From: "SK\\ssssk" Date: Mon, 30 Sep 2024 21:54:10 +0900 Subject: [PATCH 02/16] =?UTF-8?q?feat:=20headerSidebar=EA=B0=80=20?= =?UTF-8?q?=EB=B3=B4=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20body=20=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=20=EB=B6=80=EB=B6=84=20=EC=8A=A4=ED=81=AC=EB=A1=A4=20?= =?UTF-8?q?=EC=9B=80=EC=A7=81=EC=9D=B4=EC=A7=80=20=EB=AA=BB=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/containers/common/HeaderContainer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/common/HeaderContainer.tsx b/src/containers/common/HeaderContainer.tsx index 20073a69..f64fac7e 100644 --- a/src/containers/common/HeaderContainer.tsx +++ b/src/containers/common/HeaderContainer.tsx @@ -1,8 +1,6 @@ "use client"; import Header from "@/components/common/Header"; -import useModalState from "@/hooks/useModalState"; -import useOutsideClick from "@/hooks/useOutsideClick"; import usePreventBodyScroll from "@/hooks/usePreventBodyScroll"; import useAuthStore from "@/store/authStore"; import { fetchWithAuth } from "@/utils/fetchWithAuth"; @@ -15,6 +13,8 @@ const HeaderContainer = () => { const [transparent, setTransparent] = useState(true); const authStore = useAuthStore(); + usePreventBodyScroll(visible); + const onScroll = () => { if (window.scrollY >= 500) { setTransparent(false); From c254f2de2c5d324bca441d82a967280353849824 Mon Sep 17 00:00:00 2001 From: "SK\\ssssk" Date: Mon, 30 Sep 2024 21:55:23 +0900 Subject: [PATCH 03/16] =?UTF-8?q?feat:=20=ED=97=A4=EB=8D=94=20=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=EB=B0=94=20=EC=8A=A4=ED=81=AC=EB=A1=A4=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/HeaderSidebar.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/common/HeaderSidebar.tsx b/src/components/common/HeaderSidebar.tsx index 8767e507..9a348915 100644 --- a/src/components/common/HeaderSidebar.tsx +++ b/src/components/common/HeaderSidebar.tsx @@ -1,7 +1,6 @@ import Image from "next/image"; import Link from "next/link"; import { Dispatch, SetStateAction } from "react"; -import { CiLogout } from "react-icons/ci"; import { MdClose } from "react-icons/md"; interface Props { @@ -28,7 +27,7 @@ const HeaderSidebar = ({ onClick={closeWithFadeOut} className={`${animationFlag ? "animate-sidebarFadeOut" : "animate-sidebarFadeIn"} fixed left-0 top-0 z-50 flex h-[200%] w-full flex-row justify-end bg-black/25`} > -