Re-authenticate in place when the Perforce ticket expires
Perforce ends the ticket on its own schedule, so a long day outlives a login. Every command then failed and the only way back was Exit + restart, which threw away the scope, selection and open panels. - p4.ts routes all ~110 commands through one invoke wrapper that recognises an auth failure (isAuthError) and raises onAuthLost, so no call site can miss it. p4_login / p4_restore / p4_clients are exempt: they report bad credentials inline and would otherwise loop the prompt. - The server poll no longer treats an expired ticket as an outage. The server answered, it just refused us — the offline banner it used to raise never cleared, since polling stayed refused forever. - ReauthModal asks for the password over the running app, keeping all state, and offers Sign out as the way back to the Connect screen. The failed command is NOT retried automatically — re-auth then refresh only. Replaying a half-finished submit or revert unattended is worse than asking. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
73
src/App.tsx
73
src/App.tsx
@ -9,7 +9,7 @@ import ModelViewer from "./ModelViewer";
|
||||
import CodeView from "./CodeView";
|
||||
import { useUpdater } from "./Updater";
|
||||
import "./App.css";
|
||||
import { p4, statusOf, splitPath, kindOf, isCodeFile, fmtTime, describeFiles, filelogRevs, humanSize, leaf, syncSummary, saveSession, loadSession, clearSession, saveScope, loadScope, recentScopes, pushRecentScope, fileBytes, getEditor, setEditorPref, P4Info, OpenedFile, Client, Change, Session, Describe, Dir, User, Editor, FileRev, FsEntry, PluginInfo } from "./p4";
|
||||
import { p4, statusOf, splitPath, kindOf, isCodeFile, fmtTime, describeFiles, filelogRevs, humanSize, leaf, syncSummary, isAuthError, onAuthLost, saveSession, loadSession, clearSession, saveScope, loadScope, recentScopes, pushRecentScope, fileBytes, getEditor, setEditorPref, P4Info, OpenedFile, Client, Change, Session, Describe, Dir, User, Editor, FileRev, FsEntry, PluginInfo } from "./p4";
|
||||
import { t, LANG, LANGS, setLangGlobal, Lang } from "./i18n";
|
||||
import { Theme, THEME_TOKENS, BUILTIN_THEMES, allThemes, loadCustomThemes, saveCustomThemes, loadActiveId, saveActiveId, resolveTheme, applyTheme, tokenValue, newCustomId, exportTheme, importTheme } from "./themes";
|
||||
import { loadPlugins, getRegistry, subscribeRegistry, runSubmitHooks, PluginView, PluginDock, fetchRegistry, installFromRegistry, RegistryEntry } from "./plugins";
|
||||
@ -408,6 +408,7 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
const [needResolve, setNeedResolve] = useState<OpenedFile[]>([]); // files awaiting conflict resolution
|
||||
const [resolveOpen, setResolveOpen] = useState(false);
|
||||
const [offline, setOffline] = useState(false); // lost connection to the server
|
||||
const [reauth, setReauth] = useState(false); // p4 ticket expired — prompt for the password
|
||||
const [workOffline, setWorkOffline] = useState(() => { try { return localStorage.getItem("exd-workoffline") === "1"; } catch { return false; } }); // explicit offline-work mode
|
||||
const [behind, setBehind] = useState<{ count: number; sample: string[] } | null>(null); // server has newer content than the workspace
|
||||
const lastSubmit = useRef<string>(""); // newest submitted CL seen (new-submit toast)
|
||||
@ -674,6 +675,8 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
if (loaded) flash(t("{n} plugin(s) loaded", { n: loaded }));
|
||||
})().catch(() => {});
|
||||
}, [info?.clientName]); // eslint-disable-line
|
||||
// any p4 command that comes back "not logged in" raises the re-auth prompt
|
||||
useEffect(() => { onAuthLost(() => setReauth(true)); return () => onAuthLost(null); }, []);
|
||||
useEffect(() => subscribeRegistry(() => setPluginVer((v) => v + 1)), []);
|
||||
// live Perforce command log — the Rust backend emits one event per p4 call
|
||||
useEffect(() => {
|
||||
@ -796,7 +799,10 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
checkBehind(); // a new submit landed → am I now behind?
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
} catch (e) {
|
||||
// an expired ticket is not an outage: the server answered, it just
|
||||
// refused us. The re-auth prompt handles it — don't also claim offline.
|
||||
if (isAuthError(e)) return;
|
||||
if (alive && !offline) setOffline(true); // p4 unreachable → show offline banner
|
||||
}
|
||||
};
|
||||
@ -1804,6 +1810,10 @@ function Workbench({ info, session, light, toggleTheme, themeId, setThemeId, lan
|
||||
{showXfer && transfer && xferMin && <TransferChip transfer={transfer} onExpand={() => setXferMin(false)} onCancel={cancelTransfer} />}
|
||||
{buildPick && <BuildPicker onPick={buildSln} onClose={() => setBuildPick(false)} />}
|
||||
{buildOpen && !buildMin && <BuildOverlay lines={buildLog} building={building} ok={buildOk} sln={slnPath} onMinimize={() => setBuildMin(true)} onClose={() => setBuildOpen(false)} />}
|
||||
{/* last in the tree so it sits over every other overlay — nothing else
|
||||
can succeed until the session is back */}
|
||||
{reauth && <ReauthModal session={session} onSignOut={onDisconnect}
|
||||
onDone={(i) => { setReauth(false); setOffline(false); onInfo(i); flash(t("Reconnected to the server.")); void refresh(); }} />}
|
||||
{buildOpen && buildMin && <BuildChip building={building} ok={buildOk} onExpand={() => setBuildMin(false)} onClose={() => setBuildOpen(false)} />}
|
||||
{ctx && <ContextMenu x={ctx.x} y={ctx.y} items={ctx.items} onClose={() => setCtx(null)} />}
|
||||
{toast && <div className={"toast" + (toast.err ? " err" : "")}>{toast.text}</div>}
|
||||
@ -2406,6 +2416,65 @@ function TextPrompt({ title, label, value, onSave, onClose }: { title: string; l
|
||||
);
|
||||
}
|
||||
|
||||
/* ---------------- re-authenticate (expired ticket) ----------------
|
||||
Perforce expires the login ticket on its own schedule, so a long day
|
||||
outlives it and every command starts failing. The server is still there and
|
||||
the workspace is untouched — only the ticket died — so we ask for the
|
||||
password over the running app instead of dropping back to the Connect
|
||||
screen, which would throw away the scope, selection and open panels.
|
||||
Deliberately not dismissable by clicking away: nothing works until it's
|
||||
resolved one way or the other. */
|
||||
function ReauthModal({ session, onDone, onSignOut }: {
|
||||
session: Session | null; onDone: (i: P4Info) => void; onSignOut: () => void;
|
||||
}) {
|
||||
const [password, setPassword] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [err, setErr] = useState("");
|
||||
const ref = useRef<HTMLInputElement>(null);
|
||||
useEffect(() => { ref.current?.focus(); }, []);
|
||||
|
||||
async function reconnect() {
|
||||
if (!session || !password || busy) return;
|
||||
setBusy(true); setErr("");
|
||||
try {
|
||||
const i = await p4.login(session.server, session.user, password, session.client);
|
||||
setPassword("");
|
||||
onDone(i);
|
||||
} catch (e) { setErr(String(e)); setBusy(false); }
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="modal-back">
|
||||
<div className="modal-card prompt" onClick={(e) => e.stopPropagation()}>
|
||||
<h3>{t("Session expired")}</h3>
|
||||
<div className="prompt-label">
|
||||
{t("Perforce ended the session. Sign in again to carry on — your workspace and open changes are untouched.")}
|
||||
</div>
|
||||
<div className="reauth-who">
|
||||
<span>{session?.user}</span>
|
||||
<span>{session?.client}</span>
|
||||
<span>{session?.server}</span>
|
||||
</div>
|
||||
<div className="fld"><label>{t("Password")}</label>
|
||||
<div className="inp">
|
||||
<svg viewBox="0 0 24 24" fill="none"><rect x="4" y="10" width="16" height="10" rx="2" stroke="currentColor" strokeWidth="1.6" /><path d="M8 10V7a4 4 0 0 1 8 0v3" stroke="currentColor" strokeWidth="1.6" /></svg>
|
||||
<input ref={ref} type="password" value={password} disabled={busy}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && reconnect()} />
|
||||
</div>
|
||||
</div>
|
||||
{err && <div className="err"><span>⚠</span><span>{err}</span></div>}
|
||||
<div className="modal-actions">
|
||||
<button className="mbtn ghost" onClick={onSignOut} disabled={busy}>{t("Sign out")}</button>
|
||||
<button className="mbtn primary" onClick={reconnect} disabled={busy || !password}>
|
||||
{busy ? t("Connecting…") : t("Reconnect")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ---------------- confirm modal ---------------- */
|
||||
function ConfirmModal({ title, body, confirm, danger, onClose }: { title: string; body: string; confirm: string; danger?: boolean; onClose: (v: boolean) => void }) {
|
||||
const btn = useRef<HTMLButtonElement>(null);
|
||||
|
||||
Reference in New Issue
Block a user