Add re-auth y/N confirmation across auth provider commands

This commit is contained in:
William Valentin
2026-02-15 20:00:11 -08:00
parent 22930cbe2e
commit e0f2d27247
7 changed files with 354 additions and 8 deletions
+13 -2
View File
@@ -26,6 +26,14 @@ async function promptHidden(question: string): Promise<string> {
return answer.trim();
}
async function promptYesNo(question: string): Promise<boolean> {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });
const answer = await new Promise<string>((resolve) => rl.question(question, resolve));
rl.close();
const normalized = answer.trim().toLowerCase();
return normalized === 'y' || normalized === 'yes';
}
export function registerOpenaiKeyCommand(program: Command): void {
program
.command('openai-key')
@@ -34,8 +42,11 @@ export function registerOpenaiKeyCommand(program: Command): void {
const existing = loadStoredOpenAIApiKey();
if (existing) {
console.log('OpenAI API key already exists.');
console.log('Delete ~/.config/flynn/auth.json openai.api_key entry if you want to re-authenticate.');
process.exit(0);
const confirmed = await promptYesNo('Re-authenticate and replace it? (y/N): ');
if (!confirmed) {
console.log('Cancelled.');
process.exit(0);
}
}
console.log('OpenAI uses API keys for standard API access.');