1+ "use client"
2+
13import {
24 Sidebar ,
35 SidebarContent ,
@@ -10,9 +12,13 @@ import {
1012 SidebarMenuButton ,
1113 SidebarMenuItem
1214} from "@/components/ui/sidebar" ;
13- import { Home , Inbox , Settings , User } from "lucide-react" ;
15+ import { Home , Inbox , User } from "lucide-react" ;
1416import Image from "next/image" ;
1517import Link from "next/link" ;
18+ import { Button } from "@/components/ui/button" ;
19+ import { logout } from "@/app/(with-layout)/_shared/services/logout-api" ;
20+ import { useRouter } from "next/navigation" ;
21+ import { useState } from "react" ;
1622
1723// Menu items.
1824const items = [
@@ -30,15 +36,28 @@ const items = [
3036 title : "회원관리" ,
3137 url : "/member" ,
3238 icon : User ,
33- } ,
34- {
35- title : "로그아웃" ,
36- url : "/logout" ,
37- icon : Settings
3839 }
3940]
4041
4142export default function AppSidebar ( ) {
43+ const router = useRouter ( ) ;
44+ const [ loading , setLoading ] = useState < boolean > ( false ) ;
45+
46+ const onClickLogout = async ( ) => {
47+ if ( loading ) {
48+ return ;
49+ }
50+ setLoading ( true ) ;
51+ try {
52+ await logout ( ) ;
53+ localStorage . removeItem ( 'accessToken' ) ;
54+ localStorage . removeItem ( 'refreshToken' ) ;
55+ router . replace ( '/login' ) ;
56+ } finally {
57+ setLoading ( false ) ;
58+ }
59+ }
60+
4261 return (
4362 < Sidebar >
4463 < SidebarHeader >
@@ -66,7 +85,19 @@ export default function AppSidebar() {
6685 </ SidebarGroupContent >
6786 </ SidebarGroup >
6887 </ SidebarContent >
69- < SidebarFooter />
88+ < SidebarFooter >
89+ < SidebarMenuItem key = "로그아웃" >
90+ < SidebarMenuButton asChild >
91+ < Button
92+ className = "hover:cursor-pointer"
93+ onClick = { onClickLogout }
94+ disabled = { loading }
95+ >
96+ { loading ? "로그아웃 중..." : "로그아웃" }
97+ </ Button >
98+ </ SidebarMenuButton >
99+ </ SidebarMenuItem >
100+ </ SidebarFooter >
70101 </ Sidebar >
71- )
102+ ) ;
72103} ;
0 commit comments