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
+14 -2
View File
@@ -1,6 +1,15 @@
import type { Command } from 'commander';
import readline from 'readline';
import { loadStoredOpenAIAuth, loginOpenAI } from '../auth/index.js';
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 registerOpenaiAuthCommand(program: Command): void {
program
.command('openai-auth')
@@ -9,8 +18,11 @@ export function registerOpenaiAuthCommand(program: Command): void {
const existing = loadStoredOpenAIAuth();
if (existing) {
console.log('OpenAI OAuth token already exists.');
console.log('Delete ~/.config/flynn/auth.json openai 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('Starting OpenAI OAuth device flow...');