mirror of
https://github.com/fccview/cronmaster.git
synced 2026-01-03 03:18:59 -05:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { Button } from "./Button";
|
|
import { LogOut } from "lucide-react";
|
|
|
|
|
|
export const LogoutButton = () => {
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const router = useRouter();
|
|
|
|
const handleLogout = async () => {
|
|
setIsLoading(true);
|
|
try {
|
|
const response = await fetch("/api/auth/logout", {
|
|
method: "POST",
|
|
});
|
|
|
|
if (response.ok) {
|
|
router.push("/login");
|
|
router.refresh();
|
|
}
|
|
} catch (error) {
|
|
console.error("Logout error:", error);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={handleLogout}
|
|
disabled={isLoading}
|
|
title="Logout"
|
|
>
|
|
<LogOut className="h-[1.2rem] w-[1.2rem]" />
|
|
<span className="sr-only">Logout</span>
|
|
</Button>
|
|
);
|
|
};
|