Skip to content

Commit

Permalink
feat: 로컬 스토리지에 jwt토큰 존재할 경우 로그인, 회원가입, 로그아웃 버튼 조건부 렌더링
Browse files Browse the repository at this point in the history
  • Loading branch information
YearaChoi committed Aug 3, 2024
1 parent 7ab3f46 commit 826da09
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/components/Common/HeaderLightVer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LoginModal from "../MainPage/LoginModal";
function HeaderLightVer() {
const [isLoginModalOpen, setLoginModalOpen] = useState(false);
const navigate = useNavigate();
const token = localStorage.getItem("jwtToken");

const handleMenuClick = (url) => {
navigate(url);
Expand All @@ -29,6 +30,8 @@ function HeaderLightVer() {
navigate("/sign");
};

const handleSignOutBtnClick = () => {};

return (
<Wrapper>
<Menus>
Expand All @@ -44,8 +47,14 @@ function HeaderLightVer() {
</Logo>
</Menus>
<SignInSection>
<SignIn onClick={toggleLoginModal}>로그인</SignIn>
<SignIn onClick={handleSignInClick}>회원가입</SignIn>
{!token ? (
<>
<SignIn onClick={toggleLoginModal}>로그인</SignIn>
<SignIn onClick={handleSignInClick}>회원가입</SignIn>
</>
) : (
<SignOut onClick={handleSignOutBtnClick}>로그아웃</SignOut>
)}
</SignInSection>
{isLoginModalOpen && <LoginModal toggleModal={toggleLoginModal} />}
<SearchSection>
Expand Down Expand Up @@ -138,3 +147,11 @@ const SignIn = styled.div`
font-size: 14px;
cursor: pointer;
`;

const SignOut = styled.div`
color: #1997fc;
font-size: 14px;
cursor: pointer;
/* border: 1px solid red; */
margin-left: 70px;
`;
22 changes: 20 additions & 2 deletions src/components/MainPage/HeaderMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LoginModal from "./LoginModal";
function HeaderMain() {
const [isLoginModalOpen, setLoginModalOpen] = useState(false);
const navigate = useNavigate();
const token = localStorage.getItem("jwtToken");

const toggleLoginModal = () => {
setLoginModalOpen((prevState) => !prevState);
Expand All @@ -17,6 +18,8 @@ function HeaderMain() {
navigate("/sign");
};

const handleSignOutBtnClick = () => {};

useEffect(() => {
document.body.style.overflow = isLoginModalOpen ? "hidden" : "auto";
}, [isLoginModalOpen]);
Expand Down Expand Up @@ -44,8 +47,14 @@ function HeaderMain() {
</Logo>
</Menus>
<SignInSection>
<SignIn onClick={toggleLoginModal}>로그인</SignIn>
<SignIn onClick={handleSignInClick}>회원가입</SignIn>
{!token ? (
<>
<SignIn onClick={toggleLoginModal}>로그인</SignIn>
<SignIn onClick={handleSignInClick}>회원가입</SignIn>
</>
) : (
<SignOut onClick={handleSignOutBtnClick}>로그아웃</SignOut>
)}
</SignInSection>
{isLoginModalOpen && <LoginModal toggleModal={toggleLoginModal} />}
<SearchSection>
Expand Down Expand Up @@ -131,10 +140,19 @@ const SignInSection = styled.div`
top: 30%;
transform: translateX(-50%);
z-index: 1;
/* border: 1px solid red; */
`;

const SignIn = styled.div`
color: #1997fc;
font-size: 14px;
cursor: pointer;
`;

const SignOut = styled.div`
color: #1997fc;
font-size: 14px;
cursor: pointer;
/* border: 1px solid red; */
margin-left: 70px;
`;

0 comments on commit 826da09

Please sign in to comment.