From 050c4819f70b28dd6ffd3c7a95078dd2cea609fc Mon Sep 17 00:00:00 2001 From: bentshrimp Date: Thu, 5 Oct 2023 23:44:50 +0900 Subject: [PATCH 1/3] Fix : remove user info in local storage #83 - correct the icon src - remove user info every time user revisit after automatic loggout Signed-off-by: bentshrimp --- public/index.html | 2 +- src/pages/MainPage.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index f6ace053..92543d29 100644 --- a/public/index.html +++ b/public/index.html @@ -2,7 +2,7 @@ - + { - setIsLogin(await checkTokenValid()); + const loggedIn = await checkTokenValid(); + if (loggedIn) { + localStorage.removeItem("id"); + localStorage.removeItem("name"); + localStorage.removeItem("avatar"); + } + setIsLogin(loggedIn); }; useEffect(() => { From 46c52b12dec3e98ba8f289e7685752ddda64dfd2 Mon Sep 17 00:00:00 2001 From: bentshrimp Date: Sat, 7 Oct 2023 01:11:57 +0900 Subject: [PATCH 2/3] Fix : render profile image when only login #83 Signed-off-by: bentshrimp --- src/layout/Header.js | 12 +++++++----- src/pages/MainPage.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/layout/Header.js b/src/layout/Header.js index a4272da7..6b006f31 100644 --- a/src/layout/Header.js +++ b/src/layout/Header.js @@ -48,11 +48,13 @@ export const Header = (props) => { const [src, setSrc] = useRecoilState(avatar); const [userId, setUserId] = useRecoilState(id); const [userName, setUserName] = useRecoilState(name); - const setIsLogin = useSetRecoilState(isLogin); + const [Login, setLogin] = useRecoilState(isLogin); React.useEffect(() => { - setSrc(localStorage.avatar); - setUserId(localStorage.id); - setUserName(localStorage.name); + if (Login) { + setSrc(localStorage.avatar); + setUserId(localStorage.id); + setUserName(localStorage.name); + } }, []); const handleOpenNavMenu = (event) => { setAnchorElNav(event.currentTarget); @@ -76,7 +78,7 @@ export const Header = (props) => { "", { withCredentials: true }, ); - setIsLogin(false); + setLogin(false); localStorage.setItem("id", "guest"); localStorage.setItem("name", "guest"); localStorage.setItem("avatar", ""); diff --git a/src/pages/MainPage.js b/src/pages/MainPage.js index f9ed7a21..55af9ff2 100644 --- a/src/pages/MainPage.js +++ b/src/pages/MainPage.js @@ -26,7 +26,7 @@ function MainPage() { const checkIsLogin = async () => { const loggedIn = await checkTokenValid(); - if (loggedIn) { + if (!loggedIn) { localStorage.removeItem("id"); localStorage.removeItem("name"); localStorage.removeItem("avatar"); From 4d14dea7608d29ce5d1e3b43d1d0f586119836a0 Mon Sep 17 00:00:00 2001 From: bentshrimp Date: Sat, 7 Oct 2023 01:17:09 +0900 Subject: [PATCH 3/3] Chore : remove unnecessary import #83 Signed-off-by: bentshrimp --- src/layout/Header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layout/Header.js b/src/layout/Header.js index 6b006f31..c3e9cdfb 100644 --- a/src/layout/Header.js +++ b/src/layout/Header.js @@ -17,7 +17,7 @@ import MenuItem from "@mui/material/MenuItem"; import MenuIcon from "@mui/icons-material/Menu"; import LOGO from "../../src/assets/images/Logo.svg"; import axios from "axios"; -import { useRecoilState, useSetRecoilState } from "recoil"; +import { useRecoilState } from "recoil"; import { avatar, id, name, isLogin } from "../recoil/authorize"; import styled from "styled-components"; const ElevationScroll = (props) => {