Skip to content

Commit 471a8cb

Browse files
julianknutsenclaude
andcommitted
fix: persist impersonation handle in sessionStorage to survive reload
The staging impersonation UI triggered window.location.reload() after setting the handle, but the handle was only stored in a module-level variable that was lost on reload. Now persisted in sessionStorage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c6dba20 commit 471a8cb

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

web/src/api/client.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,31 @@ export function getActiveUpstream(): string | null {
3333
return _activeUpstream;
3434
}
3535

36-
// --- Staging impersonation ---
36+
// --- Staging impersonation (persisted in sessionStorage to survive reloads) ---
3737

38-
let _impersonateHandle: string | null = null;
38+
const IMPERSONATE_KEY = "wl_impersonate";
39+
40+
function loadImpersonation(): string | null {
41+
try {
42+
return sessionStorage.getItem(IMPERSONATE_KEY) || null;
43+
} catch {
44+
return null;
45+
}
46+
}
47+
48+
let _impersonateHandle: string | null = loadImpersonation();
3949

4050
export function setImpersonation(handle: string | null) {
4151
_impersonateHandle = handle;
52+
try {
53+
if (handle) {
54+
sessionStorage.setItem(IMPERSONATE_KEY, handle);
55+
} else {
56+
sessionStorage.removeItem(IMPERSONATE_KEY);
57+
}
58+
} catch {
59+
// sessionStorage unavailable — in-memory only
60+
}
4261
}
4362

4463
export function getImpersonation(): string | null {

0 commit comments

Comments
 (0)