fix(ui): use effective management secret in control panel embed

- Fetch auth tokens from /api/settings/auth/tokens/raw
- Use effective management secret for local mode auto-login
- Remove hardcoded CCS_CONTROL_PANEL_SECRET constant
- Key hint now shows correct secret (custom or default)
This commit is contained in:
kaitranntt committed 2025-12-25 17:15:00 -05:00
1 parent 7e031b5097
commit a762563f1b
1 file changed
+19 -5
@@ -15,8 +15,10 @@ import type { CliproxyServerConfig } from '@/lib/api-client';
/** CLIProxyAPI default port */ /** CLIProxyAPI default port */
const CLIPROXY_DEFAULT_PORT = 8317; const CLIPROXY_DEFAULT_PORT = 8317;
/** CCS Control Panel secret - must match config-generator.ts CCS_CONTROL_PANEL_SECRET */ interface AuthTokensResponse {
const CCS_CONTROL_PANEL_SECRET = 'ccs'; apiKey: { value: string; isCustom: boolean };
managementSecret: { value: string; isCustom: boolean };
}
interface ControlPanelEmbedProps { interface ControlPanelEmbedProps {
port?: number; port?: number;
@@ -36,6 +38,17 @@ export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanel
staleTime: 30000, // 30 seconds staleTime: 30000, // 30 seconds
}); });
// Fetch auth tokens for local mode (gets effective management secret)
const { data: authTokens } = useQuery<AuthTokensResponse>({
queryKey: ['auth-tokens-raw'],
queryFn: async () => {
const response = await fetch('/api/settings/auth/tokens/raw');
if (!response.ok) throw new Error('Failed to fetch auth tokens');
return response.json();
},
staleTime: 30000, // 30 seconds
});
// Log config fetch errors (fallback to local mode on error) // Log config fetch errors (fallback to local mode on error)
useEffect(() => { useEffect(() => {
if (configError) { if (configError) {
@@ -67,15 +80,16 @@ export function ControlPanelEmbed({ port = CLIPROXY_DEFAULT_PORT }: ControlPanel
}; };
} }
// Local mode // Local mode - use effective management secret from auth tokens API
const effectiveSecret = authTokens?.managementSecret?.value || 'ccs';
return { return {
managementUrl: `http://localhost:${port}/management.html`, managementUrl: `http://localhost:${port}/management.html`,
checkUrl: `http://localhost:${port}/`, checkUrl: `http://localhost:${port}/`,
authToken: CCS_CONTROL_PANEL_SECRET, authToken: effectiveSecret,
isRemote: false, isRemote: false,
displayHost: `localhost:${port}`, displayHost: `localhost:${port}`,
}; };
}, [cliproxyConfig, port]); }, [cliproxyConfig, authTokens, port]);
// Check if CLIProxy is running // Check if CLIProxy is running
useEffect(() => { useEffect(() => {