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
+5
View File
@@ -86,15 +86,20 @@ async def login(
@router.get("/me")
async def me(
request: Request,
username: Annotated[str, Depends(require_control_user)],
settings: Annotated[ControlSettings, Depends(get_control_settings)],
) -> dict:
ip = client_ip(request)
lan = is_lan_ip(ip)
return {
"username": username,
"poll_interval_sec": settings.control_poll_interval_sec,
"sse_interval_sec": settings.control_sse_interval_sec,
"show_default_hint": settings.is_default_credentials,
"lan_bypass_enabled": settings.lan_auth_bypass,
"lan_client": lan,
"client_ip": ip or None,
}
+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>