From 4f34440e4e33822f8dcc2a0052fdaffaff4ba5f4 Mon Sep 17 00:00:00 2001 From: Yun Min Woo Date: Sat, 7 Oct 2023 01:27:56 +0900 Subject: [PATCH] Revert "Unexpected bugs fixed" --- src/layout/Header.js | 14 ++++++-------- src/pages/MainPage.js | 8 +------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/layout/Header.js b/src/layout/Header.js index c089e917..fa06854f 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 } from "recoil"; +import { useRecoilState, useSetRecoilState } from "recoil"; import { avatar, id, name, isLogin } from "../recoil/authorize"; import styled from "styled-components"; const ElevationScroll = (props) => { @@ -48,13 +48,11 @@ export const Header = (props) => { const [src, setSrc] = useRecoilState(avatar); const [userId, setUserId] = useRecoilState(id); const [userName, setUserName] = useRecoilState(name); - const [Login, setLogin] = useRecoilState(isLogin); + const setIsLogin = useSetRecoilState(isLogin); React.useEffect(() => { - if (Login) { - setSrc(localStorage.avatar); - setUserId(localStorage.id); - setUserName(localStorage.name); - } + setSrc(localStorage.avatar); + setUserId(localStorage.id); + setUserName(localStorage.name); }, []); const handleOpenNavMenu = (event) => { setAnchorElNav(event.currentTarget); @@ -78,7 +76,7 @@ export const Header = (props) => { "", { withCredentials: true }, ); - setLogin(false); + setIsLogin(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 55af9ff2..f994f518 100644 --- a/src/pages/MainPage.js +++ b/src/pages/MainPage.js @@ -25,13 +25,7 @@ function MainPage() { const setIsLogin = useSetRecoilState(isLogin); const checkIsLogin = async () => { - const loggedIn = await checkTokenValid(); - if (!loggedIn) { - localStorage.removeItem("id"); - localStorage.removeItem("name"); - localStorage.removeItem("avatar"); - } - setIsLogin(loggedIn); + setIsLogin(await checkTokenValid()); }; useEffect(() => {