diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 007e352..51f48e6 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -2,15 +2,19 @@ import { useRouter } from 'next/router'; import styled from '@emotion/styled'; import Icon from '@components/Icon'; -import { useContext } from 'react'; +import { useContext, useState } from 'react'; import Image from 'next/image'; import ProfileContext from '@contexts/ProfileContext'; +import authAPI from '@apis/authAPI'; +import Cookies from 'js-cookie'; const Header = () => { const router = useRouter(); const profileContext = useContext(ProfileContext); + const [clickDropdown, setClickDropdown] = useState(false); + // 로그인을 누른 url 저장 const handleLink = () => { if (!router.asPath.includes('login?callback=')) { @@ -18,11 +22,29 @@ const Header = () => { } }; + const handleDropDown = () => { + setClickDropdown((prev) => !prev); + }; + + const moveToMypage = () => { + router.push('/mypage'); + }; + + const handleLogout = async () => { + try { + const res = await authAPI({ method: 'post', url: '/api/member/logout' }); + Cookies.remove('accessToken'); + Cookies.remove('refreshToken'); + + router.push('/'); + } catch (error) {} + }; + return ( {profileContext?.profile ? ( - + { alt='profile' /> {profileContext.profile.nickname} + + 마이페이지 + 로그아웃 + ) : ( @@ -56,6 +82,8 @@ const Container = styled.div` display: flex; align-items: center; justify-content: flex-end; + + position: relative; `; const ProfileImg = styled(Image)` @@ -78,3 +106,31 @@ const Text = styled.div` font-size: 1.4rem; font-weight: 900; `; + +const DropDown = styled.ul<{ click: boolean }>` + position: absolute; + + display: ${(prop) => (prop.click ? 'block' : 'none')}; + + width: 10rem; + + top: 5.5rem; + right: 0rem; + + color: black; +`; + +const DropList = styled.li` + list-style: none; + + align-items: center; + justify-content: center; + + display: flex; + + background-color: #344051; + color: white; + + height: 4rem; + border: 1px solid black; +`;