fix(dashboard): clear local control-panel management key (#1372)

This commit is contained in:
Kai (Tam Nhu) Tran
2026-05-23 21:44:53 -04:00
committed by GitHub
parent e6f764c79b
commit 6c0f7ac39c
2 changed files with 18 additions and 0 deletions
@@ -57,6 +57,10 @@ function clearLocalControlPanelSession(): void {
window.localStorage.removeItem(CONTROL_PANEL_LOGIN_FLAG_KEY);
}
function clearPersistedLocalControlPanelSecret(): void {
window.localStorage.removeItem(CONTROL_PANEL_MANAGEMENT_KEY);
}
export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanelEmbedProps) {
const { t } = useTranslation();
const iframeRef = useRef<HTMLIFrameElement>(null);
@@ -162,7 +166,13 @@ export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanel
return;
}
const handleBeforeUnload = () => {
clearLocalControlPanelSession();
};
window.addEventListener('beforeunload', handleBeforeUnload);
return () => {
window.removeEventListener('beforeunload', handleBeforeUnload);
clearLocalControlPanelSession();
};
}, [isRemote]);
@@ -266,9 +276,15 @@ export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanel
const handleIframeLoad = () => {
setLoadedFrameKey(iframeKey);
postRemoteAutoLoginCredentials();
if (!isRemote) {
clearPersistedLocalControlPanelSecret();
}
};
const handleRefresh = () => {
if (!isRemote) {
clearLocalControlPanelSession();
}
setLoadedFrameKey(null);
setIframeRevision((value) => value + 1);
setError(null);
@@ -94,6 +94,7 @@ describe('ControlPanelEmbed', () => {
const iframe = await screen.findByTitle('CLIProxy Management Panel');
expect(iframe).toHaveAttribute('src', '/api/cliproxy-local/management.html');
fireEvent.load(iframe);
await waitFor(() => {
expect(window.localStorage.removeItem).toHaveBeenCalledWith('cli-proxy-auth');
@@ -107,6 +108,7 @@ describe('ControlPanelEmbed', () => {
);
expect(window.localStorage.setItem).toHaveBeenCalledWith('managementKey', 'custom-secret');
expect(window.localStorage.setItem).toHaveBeenCalledWith('isLoggedIn', 'true');
expect(window.localStorage.removeItem).toHaveBeenCalledWith('managementKey');
});
vi.clearAllMocks();