Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { saveCredentials, getConfigDirectoryPath } from '../utils/credentials';
import { updateConfig } from '../utils/config';
import { updateConfig, getApiKey } from '../utils/config';
import {
browserLogin,
manualLogin,
Expand Down Expand Up @@ -42,6 +42,27 @@ export async function handleLoginCommand(
return;
}

// If only a custom --api-url is provided (no --api-key), persist the new URL
// alongside the existing API key rather than starting an interactive login flow.
if (isCustomUrl && !options.apiKey && !options.method) {
const existingApiKey = getApiKey();
try {
saveCredentials({
apiKey: existingApiKey,
apiUrl: apiUrl,
});
updateConfig({ apiKey: existingApiKey, apiUrl });
console.log('✓ API URL updated successfully!');
} catch (error) {
console.error(
'Error saving credentials:',
error instanceof Error ? error.message : 'Unknown error'
);
process.exit(1);
}
return;
}

// If API key provided directly, save it
if (options.apiKey) {
// Only validate fc- prefix for cloud API
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
handleAllScrapeCommand,
} from './commands/scrape';
import { initializeConfig, updateConfig } from './utils/config';
import { getClient } from './utils/client';
import { configure, viewConfig } from './commands/config';
import { handleCreditUsageCommand } from './commands/credit-usage';
import { handleCrawlCommand } from './commands/crawl';
Expand Down Expand Up @@ -1075,9 +1074,10 @@ program
)
.option('-b, --browser', 'Login via browser (shortcut for --method browser)')
.action(async (options) => {
const globalOptions = program.opts();
await handleLoginCommand({
apiKey: options.apiKey,
apiUrl: options.apiUrl,
apiKey: options.apiKey ?? globalOptions.apiKey,
apiUrl: options.apiUrl ?? globalOptions.apiUrl,
webUrl: options.webUrl,
method: options.browser ? 'browser' : options.method,
});
Expand Down