Skip to content

Commit

Permalink
!!fix
Browse files Browse the repository at this point in the history
  • Loading branch information
03hoho03 committed Apr 8, 2024
1 parent 747512b commit e544deb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/_common/nav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ import Link from 'next/link'
import logo from '../../_assets/_images/logo.png'
import S from './nav.module.css'
import { useRouter } from 'next/navigation'
import { useEffect, useState } from 'react'

//TODO: 사용자 프로필 이미지 가져오기
function Nav() {
const router = useRouter()
const accessToken = typeof window && localStorage?.getItem('accessToken')
const [isAuth, setIsAuth] = useState(false)

useEffect(() => {
if (typeof window !== 'undefined') {
const item = localStorage.getItem('accessToken')
if (item) {
setIsAuth(true)
}
}
}, [])

const handleLogout = () => {
localStorage.removeItem('accessToken')
setIsAuth(false)
location.reload()
}
const handleLogin = () => {
Expand All @@ -24,7 +35,7 @@ function Nav() {
<Link href="/main">
<Image src={logo} alt="로고" width={100} height={100} />
</Link>
{accessToken ? (
{isAuth ? (
<button className={S.btn} type="button" onClick={handleLogout}>
로그아웃
</button>
Expand Down

0 comments on commit e544deb

Please sign in to comment.