feat: показывать баннер, если инстанс не защищён паролем

Раньше предупреждение об отсутствии AURUM_BASIC_AUTH_USER/PASSWORD
было видно только в логах docker-контейнера при старте и терялось,
если пользователь забыл настроить .env. Теперь LoginGate различает
'авторизован' и 'auth вообще не настроен' и во втором случае
показывает заметный баннер прямо в интерфейсе.
This commit is contained in:
ZProger
2026-09-10 19:34:25 +03:00
parent 19ca9c3158
commit 292ef1e410
3 changed files with 70 additions and 5 deletions

View File

@@ -1,9 +1,17 @@
import { type ReactNode, useEffect, useState } from "react";
import { Logo } from "@/components/layout/Logo";
import { LoginScreen } from "@/components/auth/LoginScreen";
import { NoAuthBanner } from "@/components/auth/NoAuthBanner";
import { checkCredentials, useAuthHeader } from "@/lib/auth";
type Probe = "checking" | "required" | "not-required";
// "not-configured" and "authenticated" both render `children` the same way,
// but they must stay distinct: only "not-configured" means this instance has
// no AURUM_BASIC_AUTH_USER/PASSWORD at all (nginx never sent 401 to our
// deliberately-wrong probe header), which is what triggers NoAuthBanner.
// Collapsing them back into one "not-required" state would make an
// authenticated session with valid stored credentials show the "this
// instance has no password" warning too.
type Probe = "checking" | "required" | "not-configured" | "authenticated";
/** Wraps the whole app. Renders the login screen only when this instance
* actually has Basic Auth turned on (AURUM_BASIC_AUTH_USER/PASSWORD in
@@ -14,11 +22,11 @@ type Probe = "checking" | "required" | "not-required";
* reactively, and this falls back to the login screen on its own. */
export function LoginGate({ children }: { children: ReactNode }) {
const authHeader = useAuthHeader();
const [probe, setProbe] = useState<Probe>(authHeader ? "not-required" : "checking");
const [probe, setProbe] = useState<Probe>(authHeader ? "authenticated" : "checking");
useEffect(() => {
if (authHeader) {
setProbe("not-required");
setProbe("authenticated");
return;
}
let cancelled = false;
@@ -27,7 +35,7 @@ export function LoginGate({ children }: { children: ReactNode }) {
// A network/backend error here isn't an auth problem — don't block
// the user behind a login screen for an unrelated outage, let the
// app's own per-page error states (e.g. dashboard.errorLoading) explain it.
setProbe(result === "unauthorized" ? "required" : "not-required");
setProbe(result === "unauthorized" ? "required" : "not-configured");
});
return () => {
cancelled = true;
@@ -46,5 +54,10 @@ export function LoginGate({ children }: { children: ReactNode }) {
return <LoginScreen />;
}
return <>{children}</>;
return (
<>
{probe === "not-configured" && <NoAuthBanner />}
{children}
</>
);
}