Hide username and logout on LAN clients in control header.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-30 13:47:50 +08:00
parent be5803332f
commit c5f477b8bc
2 changed files with 30 additions and 15 deletions
+25 -15
View File
@@ -1,4 +1,4 @@
import { type ReactNode } from "react";
import { type ReactNode, useEffect, useState } from "react";
import {
NavLink,
Navigate,
@@ -6,13 +6,21 @@ import {
Routes,
useLocation,
} from "react-router-dom";
import { clearSession, getToken, getUsername } from "./api";
import { apiFetch, clearSession, getToken, getUsername } from "./api";
import LoginPage from "./pages/Login";
import MonitorPage from "./pages/Monitor";
import SettingsPage from "./pages/Settings";
function Shell({ children }: { children: ReactNode }) {
const user = getUsername();
const [lanClient, setLanClient] = useState(false);
useEffect(() => {
apiFetch<{ lan_client?: boolean }>("/api/auth/me")
.then((m) => setLanClient(!!m.lan_client))
.catch(() => setLanClient(false));
}, []);
return (
<div className="shell">
<header className="header">
@@ -25,19 +33,21 @@ function Shell({ children }: { children: ReactNode }) {
</NavLink>
</nav>
<div className="header-right">
<span className="meta">{user}</span>
<button
type="button"
className="btn ghost"
onClick={() => {
clearSession();
window.location.href = "/login";
}}
>
退
</button>
</div>
{!lanClient ? (
<div className="header-right">
<span className="meta">{user}</span>
<button
type="button"
className="btn ghost"
onClick={() => {
clearSession();
window.location.href = "/login";
}}
>
退
</button>
</div>
) : null}
</header>
<main className="main">{children}</main>
</div>