From 3ace6b9ae438c36ef207686047ada1559f195edc Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Mon, 27 Nov 2023 16:40:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=9C=A0=EC=A7=80=20=EB=B0=95=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=20=EC=8B=9C=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EB=B7=B0=EB=A1=9C=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 로그인 유지 박스를 활용하여, 새로 고침 시 로그인이 유지될지 안 될지를 설정할 수 있도록 변경하였고, 로그인창에서 회원가입 클릭 시 회원가입 뷰로 전환하도록 클릭 이벤트를 추가하였습니다. --- FE/src/components/LoginModal/LoginModal.js | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/FE/src/components/LoginModal/LoginModal.js b/FE/src/components/LoginModal/LoginModal.js index 5d4ef76..5527d4b 100644 --- a/FE/src/components/LoginModal/LoginModal.js +++ b/FE/src/components/LoginModal/LoginModal.js @@ -14,6 +14,7 @@ import naver from "../../assets/naver.png"; function LoginModal() { const [userId, setUserId] = useState(""); + const [keepLogin, setKeepLogin] = useState(false); const [password, setPassword] = useState(""); const setUserState = useSetRecoilState(userAtom); const setHeaderState = useSetRecoilState(headerAtom); @@ -40,7 +41,9 @@ function LoginModal() { isLogin: true, accessToken: data.accessToken, })); - localStorage.setItem("accessToken", data.accessToken); + if (keepLogin) { + localStorage.setItem("accessToken", data.accessToken); + } } else { errorRef.current.innerText = data.message; } @@ -87,7 +90,11 @@ function LoginModal() { onChange={(e) => setPassword(e.target.value)} /> - +
로그인 유지
@@ -97,7 +104,15 @@ function LoginModal() { 로그인 - + { + setHeaderState((prev) => ({ + ...prev, + isLogin: false, + isSignUp: true, + })); + }} + >
회원가입
아이디/비밀번호 찾기
@@ -165,6 +180,8 @@ const HelpBar = styled.div` font-size: 1rem; color: #ffffff; + + cursor: pointer; `; const HelpBarBorder = styled.div` From dc59e3a78a04db17b0ce6bef2d8528f0f1cabda5 Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Mon, 27 Nov 2023 16:52:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=9C=A0=EC=A7=80=20sessionStorage=20=EB=8F=84=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 로그인 유지를 체크하지 않았어도 새로고침 시 로그아웃되지 않고 로그인이 유지가 되도록 하되, 탭을 종료 시 로그아웃되도록 하기 위해 체크하지 않은 경우 sessionStorage, 체크한 경우 localStorage에 저장하도록 로직을 변경했습니다. --- FE/src/App.js | 3 ++- FE/src/components/LoginModal/LoginModal.js | 2 ++ FE/src/components/SideBar/SideBar.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/FE/src/App.js b/FE/src/App.js index 3abdb82..6c8b0b8 100644 --- a/FE/src/App.js +++ b/FE/src/App.js @@ -38,7 +38,8 @@ function App() { const [userState, setUserState] = useRecoilState(userAtom); useLayoutEffect(() => { - const accessToken = localStorage.getItem("accessToken"); + let accessToken = localStorage.getItem("accessToken"); + accessToken = accessToken || sessionStorage.getItem("accessToken"); if (accessToken) { setUserState({ ...userState, isLogin: true, accessToken }); } diff --git a/FE/src/components/LoginModal/LoginModal.js b/FE/src/components/LoginModal/LoginModal.js index 5527d4b..261364c 100644 --- a/FE/src/components/LoginModal/LoginModal.js +++ b/FE/src/components/LoginModal/LoginModal.js @@ -43,6 +43,8 @@ function LoginModal() { })); if (keepLogin) { localStorage.setItem("accessToken", data.accessToken); + } else { + sessionStorage.setItem("accessToken", data.accessToken); } } else { errorRef.current.innerText = data.message; diff --git a/FE/src/components/SideBar/SideBar.js b/FE/src/components/SideBar/SideBar.js index 00aa015..755ce95 100644 --- a/FE/src/components/SideBar/SideBar.js +++ b/FE/src/components/SideBar/SideBar.js @@ -62,6 +62,7 @@ function SideBar() { accessToken: "", })); localStorage.removeItem("accessToken"); + sessionStorage.removeItem("accessToken"); }} > 로그아웃