fix: Allow testing API keys without saving first

- Add optional apiKey parameter to verifyClaudeAuth endpoint
- Backend uses provided key when available, falls back to stored key
- Frontend passes current input value to test unsaved keys
- Add input validation before testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Kacper
2025-12-29 21:39:59 +01:00
parent 6c3d3aa111
commit fa23a7b8e2
4 changed files with 46 additions and 17 deletions

View File

@@ -69,12 +69,22 @@ export function useApiKeyManagement() {
// Test Anthropic/Claude connection
const handleTestAnthropicConnection = async () => {
// Validate input first
if (!anthropicKey || anthropicKey.trim().length === 0) {
setTestResult({
success: false,
message: 'Please enter an API key to test.',
});
return;
}
setTestingConnection(true);
setTestResult(null);
try {
const api = getElectronAPI();
const data = await api.setup.verifyClaudeAuth('api_key');
// Pass the current input value to test unsaved keys
const data = await api.setup.verifyClaudeAuth('api_key', anthropicKey);
if (data.success && data.authenticated) {
setTestResult({

View File

@@ -537,7 +537,10 @@ export interface ElectronAPI {
isMac: boolean;
isLinux: boolean;
}>;
verifyClaudeAuth: (authMethod?: 'cli' | 'api_key') => Promise<{
verifyClaudeAuth: (
authMethod?: 'cli' | 'api_key',
apiKey?: string
) => Promise<{
success: boolean;
authenticated: boolean;
error?: string;
@@ -1118,7 +1121,10 @@ interface SetupAPI {
isMac: boolean;
isLinux: boolean;
}>;
verifyClaudeAuth: (authMethod?: 'cli' | 'api_key') => Promise<{
verifyClaudeAuth: (
authMethod?: 'cli' | 'api_key',
apiKey?: string
) => Promise<{
success: boolean;
authenticated: boolean;
error?: string;
@@ -1208,8 +1214,12 @@ function createMockSetupAPI(): SetupAPI {
};
},
verifyClaudeAuth: async (authMethod?: 'cli' | 'api_key') => {
console.log('[Mock] Verifying Claude auth with method:', authMethod);
verifyClaudeAuth: async (authMethod?: 'cli' | 'api_key', apiKey?: string) => {
console.log(
'[Mock] Verifying Claude auth with method:',
authMethod,
apiKey ? '(with key)' : ''
);
// Mock always returns not authenticated
return {
success: true,

View File

@@ -491,12 +491,13 @@ export class HttpApiClient implements ElectronAPI {
}> => this.get('/api/setup/platform'),
verifyClaudeAuth: (
authMethod?: 'cli' | 'api_key'
authMethod?: 'cli' | 'api_key',
apiKey?: string
): Promise<{
success: boolean;
authenticated: boolean;
error?: string;
}> => this.post('/api/setup/verify-claude-auth', { authMethod }),
}> => this.post('/api/setup/verify-claude-auth', { authMethod, apiKey }),
getGhStatus: (): Promise<{
success: boolean;