mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-10 06:20:13 +00:00
fix(dashboard): clear local control-panel management key (#1372)
This commit is contained in:
@@ -57,6 +57,10 @@ function clearLocalControlPanelSession(): void {
|
|||||||
window.localStorage.removeItem(CONTROL_PANEL_LOGIN_FLAG_KEY);
|
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) {
|
export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanelEmbedProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
@@ -162,7 +166,13 @@ export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleBeforeUnload = () => {
|
||||||
|
clearLocalControlPanelSession();
|
||||||
|
};
|
||||||
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||||
clearLocalControlPanelSession();
|
clearLocalControlPanelSession();
|
||||||
};
|
};
|
||||||
}, [isRemote]);
|
}, [isRemote]);
|
||||||
@@ -266,9 +276,15 @@ export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanel
|
|||||||
const handleIframeLoad = () => {
|
const handleIframeLoad = () => {
|
||||||
setLoadedFrameKey(iframeKey);
|
setLoadedFrameKey(iframeKey);
|
||||||
postRemoteAutoLoginCredentials();
|
postRemoteAutoLoginCredentials();
|
||||||
|
if (!isRemote) {
|
||||||
|
clearPersistedLocalControlPanelSecret();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
|
if (!isRemote) {
|
||||||
|
clearLocalControlPanelSession();
|
||||||
|
}
|
||||||
setLoadedFrameKey(null);
|
setLoadedFrameKey(null);
|
||||||
setIframeRevision((value) => value + 1);
|
setIframeRevision((value) => value + 1);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ describe('ControlPanelEmbed', () => {
|
|||||||
const iframe = await screen.findByTitle('CLIProxy Management Panel');
|
const iframe = await screen.findByTitle('CLIProxy Management Panel');
|
||||||
|
|
||||||
expect(iframe).toHaveAttribute('src', '/api/cliproxy-local/management.html');
|
expect(iframe).toHaveAttribute('src', '/api/cliproxy-local/management.html');
|
||||||
|
fireEvent.load(iframe);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(window.localStorage.removeItem).toHaveBeenCalledWith('cli-proxy-auth');
|
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('managementKey', 'custom-secret');
|
||||||
expect(window.localStorage.setItem).toHaveBeenCalledWith('isLoggedIn', 'true');
|
expect(window.localStorage.setItem).toHaveBeenCalledWith('isLoggedIn', 'true');
|
||||||
|
expect(window.localStorage.removeItem).toHaveBeenCalledWith('managementKey');
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
|||||||
Reference in New Issue
Block a user