28 lines
681 B
TypeScript
28 lines
681 B
TypeScript
"use client";
|
|||
|
|
|
||
|
|
import { useRouter } from "next/navigation";
|
||
|
|
import { useState } from "react";
|
||
|
|
|
||
|
|
import { api } from "@/lib/api";
|
||
|
|
|
||
|
|
export function LogoutButton() {
|
||
|
|
const router = useRouter();
|
||
|
|
const [busy, setBusy] = useState(false);
|
||
|
|
async function logout() {
|
||
|
|
setBusy(true);
|
||
|
|
try {
|
||
|
|
await api("/auth/logout", { method: "POST" });
|
||
|
|
} catch {
|
||
|
|
// The session may already be gone; go to the login page either way.
|
||
|
|
}
|
||
|
|
window.google?.accounts.id.disableAutoSelect();
|
||
|
|
router.replace("/belepes");
|
||
|
|
router.refresh();
|
||
|
|
}
|
||
|
|
return (
|
||
|
|
<button type="button" className="btn btn-sm" onClick={logout} disabled={busy}>
|
||
|
|
Kilépés
|
||
|
|
</button>
|
||
|
|
);
|
||
|
|
}
|