mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 01:19:31 +08:00
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import Tooltip from "@/shared/ui/Tooltip";
|
|
import { LogOut } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useTranslation } from "react-i18next";
|
|
import { logout } from "@/lib/auth";
|
|
import { useAuthStatus } from "@/hooks/useAuthStatus";
|
|
|
|
interface LogoutButtonProps {
|
|
collapsed?: boolean;
|
|
}
|
|
|
|
export function LogoutButton({ collapsed = false }: LogoutButtonProps) {
|
|
const router = useRouter();
|
|
const { t } = useTranslation();
|
|
const { enabled } = useAuthStatus();
|
|
|
|
if (!enabled) return null;
|
|
|
|
async function handleLogout() {
|
|
await logout();
|
|
router.replace("/login");
|
|
}
|
|
|
|
if (collapsed) {
|
|
return (
|
|
<Tooltip label={t("Sign out")} side="top">
|
|
<button
|
|
onClick={handleLogout}
|
|
className="rounded-lg p-2 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--background)]/50 hover:text-red-500"
|
|
aria-label={t("Sign out")}
|
|
>
|
|
<LogOut size={16} strokeWidth={1.5} />
|
|
</button>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<button
|
|
onClick={handleLogout}
|
|
className="flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13.5px] text-[var(--muted-foreground)] transition-colors hover:bg-[var(--background)]/50 hover:text-red-500"
|
|
>
|
|
<LogOut size={16} strokeWidth={1.5} />
|
|
<span>{t("Sign out")}</span>
|
|
</button>
|
|
);
|
|
}
|