Files
DeepTutor/web/components/auth/LogoutButton.tsx
Bingxi Zhao (Frank) 37049c3d33 fix(web): resolve client auth state at runtime; size proxy body for uploads
Two gaps in the PR's frontend changes:

1. Client auth awareness was permanently false. api.ts/auth.ts read
   process.env.DEEPTUTOR_AUTH_ENABLED in browser code, but Next.js only inlines
   NEXT_PUBLIC_ vars into the bundle — so the Sign-out / Admin affordances never
   rendered and apiFetch's 401 -> /login redirect never fired when auth was on.
   Resolve auth state at runtime from the backend instead: fetchAuthStatus()
   records it via setRuntimeAuthEnabled(), and components observe it through the
   new useAuthStatus() hook. Works on Docker (read-only rootfs), PyPI, and dev
   with no build-time baking. (The server-side gate in proxy.ts is unaffected.)

2. KB document uploads >10MB were truncated. All /api/* now flows through the
   proxy, whose body buffer defaults to 10MB while the backend accepts 100MB
   (DocumentValidator.MAX_FILE_SIZE). Raise experimental.proxyClientMaxBodySize
   to 110MB so uploads aren't silently cut off.

Adds a regression test that a 401 does NOT redirect when auth is disabled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 21:12:56 +08:00

46 lines
1.2 KiB
TypeScript

"use client";
import { LogOut } from "lucide-react";
import { useRouter } from "next/navigation";
import { logout } from "@/lib/auth";
import { useAuthStatus } from "@/hooks/useAuthStatus";
interface LogoutButtonProps {
collapsed?: boolean;
}
export function LogoutButton({ collapsed = false }: LogoutButtonProps) {
const router = useRouter();
const { enabled } = useAuthStatus();
if (!enabled) return null;
async function handleLogout() {
await logout();
router.replace("/login");
}
if (collapsed) {
return (
<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="Sign out"
title="Sign out"
>
<LogOut size={16} strokeWidth={1.5} />
</button>
);
}
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>Sign out</span>
</button>
);
}