로그인 UI 추가

This commit is contained in:
koreacomp5
2025-10-10 11:22:43 +09:00
parent c28698cd5c
commit 7ba8091ab9
5 changed files with 95 additions and 2 deletions

View File

@@ -1,7 +1,22 @@
"use client";
import { ThemeToggle } from "@/app/components/ThemeToggle";
import { SearchBar } from "@/app/components/SearchBar";
import { Button } from "@/app/components/ui/Button";
import React from "react";
export function AppHeader() {
const [user, setUser] = React.useState<{ nickname: string } | null>(null);
React.useEffect(() => {
fetch("/api/auth/session")
.then((r) => r.json())
.then((d) => setUser(d?.ok ? d.user : null))
.catch(() => setUser(null));
}, []);
const onLogout = async () => {
await fetch("/api/auth/session", { method: "DELETE" });
setUser(null);
location.reload();
};
return (
<header style={{ display: "flex", justifyContent: "space-between", padding: 12 }}>
<div>msg App</div>
@@ -10,6 +25,14 @@ export function AppHeader() {
<a href="/boards"></a>
<SearchBar />
<ThemeToggle />
{user ? (
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
<span>{user.nickname}</span>
<Button variant="ghost" onClick={onLogout}></Button>
</div>
) : (
<a href="/login"></a>
)}
</nav>
</header>
);