File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,8 +3,20 @@ import Link from "next/link";
33
44import { Input } from "@/components/ui/input" ;
55import Image from "next/image" ;
6+ import { getMe } from "@/lib/auth/auth.server" ;
7+ import { GetMeResponse } from "@/types/auth" ;
8+ import LogoutButton from "@/components/home/LogoutButton" ;
9+
10+ export default async function Header ( ) {
11+ let isLoggedIn : GetMeResponse [ "data" ] | null = null ;
12+
13+ try {
14+ const res = await getMe ( ) ;
15+ isLoggedIn = res . data ;
16+ } catch {
17+ isLoggedIn = null ;
18+ }
619
7- export default function Header ( ) {
820 const navLinkHover =
921 "relative inline-block transition-all duration-300 ease-in-out text-text-main hover:-translate-y-0.5 before:absolute before:-bottom-0.5 before:left-0 before:right-0 before:-z-10 before:h-0.5 before:bg-border-point before:origin-bottom before:scale-y-0 before:transform before:transition-transform before:duration-300 before:ease-in-out hover:before:scale-y-100" ;
1022
@@ -32,18 +44,23 @@ export default function Header() {
3244 { /* TODO: 유저 로그인 여부 확인 후 토글 */ }
3345 { /* 비회원일 때 */ }
3446 < div className = "space-x-8 text-zinc-500" >
35- < Link className = "hover:font-medium" href = "/sign-in" >
36- 로그인
37- </ Link >
38- < Link className = "hover:font-medium" href = "/sign-up" >
39- 회원가입
40- </ Link >
41- < Link className = "hover:font-medium" href = "/my-page/overview" >
42- 마이페이지
43- </ Link >
44- < Link className = "hover:font-medium" href = "#" >
45- 로그아웃
46- </ Link >
47+ { isLoggedIn ? (
48+ < >
49+ < LogoutButton />
50+ < Link className = "hover:font-medium" href = "/my-page/overview" >
51+ 마이페이지
52+ </ Link >
53+ </ >
54+ ) : (
55+ < >
56+ < Link className = "hover:font-medium" href = "/sign-in" >
57+ 로그인
58+ </ Link >
59+ < Link className = "hover:font-medium" href = "/sign-up" >
60+ 회원가입
61+ </ Link >
62+ </ >
63+ ) }
4764 </ div >
4865 </ div >
4966 < nav className = "space-x-15 text-xl font-semibold text-zinc-900" >
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { useRouter } from "next/navigation" ;
4+ import { logout } from "@/lib/auth/auth.client" ;
5+ import { toast } from "sonner" ;
6+
7+ export default function LogoutButton ( ) {
8+ const router = useRouter ( ) ;
9+
10+ const handleLogout = async ( ) => {
11+ try {
12+ await logout ( ) ;
13+ router . push ( "/home" ) ;
14+ router . refresh ( ) ;
15+ toast . success ( "로그아웃 되었습니다." ) ;
16+ } catch {
17+ toast . error ( "로그아웃에 실패했습니다." ) ;
18+ }
19+ } ;
20+
21+ return (
22+ < button onClick = { handleLogout } className = "cursor-pointer hover:font-medium" >
23+ 로그아웃
24+ </ button >
25+ ) ;
26+ }
You can’t perform that action at this time.
0 commit comments