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