Add re-auth y/N confirmation across auth provider commands
This commit is contained in:
+13
-2
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user