25 lines
631 B
TypeScript
25 lines
631 B
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { LogOut } from "lucide-react";
|
|
import { useState } from "react";
|
|
|
|
export function LogoutButton() {
|
|
const router = useRouter();
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function logout() {
|
|
setPending(true);
|
|
await fetch("/api/auth/logout", { method: "POST" });
|
|
router.replace("/login");
|
|
router.refresh();
|
|
}
|
|
|
|
return (
|
|
<button className="secondary-button danger" disabled={pending} onClick={logout} type="button">
|
|
<LogOut aria-hidden size={18} />
|
|
{pending ? "退出中..." : "退出登录"}
|
|
</button>
|
|
);
|
|
}
|