import "./AuthTokenRecoveryDialog.css"; import { useCallback, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { clearAuthToken, setAuthToken } from "../auth"; export interface AuthTokenRecoveryDialogProps { open: boolean; } export function AuthTokenRecoveryDialog({ open }: AuthTokenRecoveryDialogProps) { const { t } = useTranslation("app"); const [tokenInput, setTokenInput] = useState(""); const tokenInputRef = useRef(null); useEffect(() => { if (!open) return; tokenInputRef.current?.focus(); }, [open]); const handleSetToken = useCallback(() => { const token = tokenInput.trim(); if (!token) return; setAuthToken(token); window.location.reload(); }, [tokenInput]); const handleClearAndRetry = useCallback(() => { clearAuthToken(); window.location.reload(); }, []); if (!open) { return null; } return (
{ if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); } }} >

{t("auth.tokenRequired", "Authentication token required")}

{t("auth.tokenRecoveryDescription", "This dashboard session can't authenticate with the daemon. Set a replacement token or clear the current token and retry.")}

setTokenInput(event.target.value)} placeholder={t("auth.pasteToken", "Paste token")} autoComplete="off" spellCheck={false} />
); }