Skip to content

Commit cfea765

Browse files
committed
feat: 로그아웃 기능 구현
1 parent efdb8c9 commit cfea765

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

components/common/Sidebar.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
'use client';
22

33
import Link from 'next/link';
4-
import { usePathname } from 'next/navigation';
4+
import { usePathname, useRouter } from 'next/navigation';
55
import {
66
Home,
77
ClipboardList,
88
CalendarPlus,
99
CopyPlus,
1010
LogOut,
1111
} from 'lucide-react';
12+
import { signOut } from 'firebase/auth';
13+
import { auth } from '@/lib/firebase';
1214

1315
const navItems = [
1416
{ label: '홈', href: '/', icon: Home },
@@ -19,6 +21,18 @@ const navItems = [
1921

2022
const Sidebar = () => {
2123
const pathname = usePathname();
24+
const router = useRouter();
25+
26+
const handleLogout = async (): Promise<void> => {
27+
try {
28+
await signOut(auth);
29+
router.replace('/landing');
30+
router.refresh(); // 서버 컴포넌트/세션 UI 갱신
31+
} catch (err) {
32+
console.error('로그아웃 실패:', err);
33+
alert('로그아웃에 실패했습니다.');
34+
}
35+
};
2236

2337
return (
2438
<div className="fixed flex h-screen w-48 flex-col bg-white">
@@ -57,7 +71,10 @@ const Sidebar = () => {
5771
</ul>
5872
</nav>
5973
<div className="absolute bottom-0 w-full border-t border-slate-200 p-4">
60-
<button className="flex items-center gap-3 rounded-lg px-4 py-3 text-sm font-medium text-slate-700 hover:bg-slate-100">
74+
<button
75+
className="flex items-center gap-3 rounded-lg px-4 py-3 text-sm font-medium text-slate-700 hover:bg-slate-100"
76+
onClick={handleLogout}
77+
>
6178
<LogOut className="h-5 w-5 text-slate-600" />
6279
로그아웃
6380
</button>

0 commit comments

Comments
 (0)