mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 02:11:28 +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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user