Add y/N re-auth confirmation to zai-auth command
This commit is contained in:
+13
-2
@@ -27,6 +27,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 registerZaiAuthCommand(program: Command): void {
|
||||
program
|
||||
.command('zai-auth')
|
||||
@@ -35,8 +43,11 @@ export function registerZaiAuthCommand(program: Command): void {
|
||||
const existing = loadStoredZaiAuth();
|
||||
if (existing) {
|
||||
console.log('Z.AI credential already exists.');
|
||||
console.log('Delete ~/.config/flynn/auth.json zai/zhipuai 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('Z.AI uses API keys (HTTP Bearer), not an OAuth device flow.');
|
||||
|
||||
Reference in New Issue
Block a user