Restore interactive re-auth prompt for Google auth CLIs

This commit is contained in:
William Valentin
2026-02-17 16:19:12 -08:00
parent 9c9ab92e9d
commit 061b96fd68
5 changed files with 70 additions and 10 deletions
+14 -2
View File
@@ -138,6 +138,15 @@ async function openBrowser(url: string): Promise<boolean> {
});
}
async function promptYesNo(question: string): Promise<boolean> {
const readline = await import('readline');
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';
}
/** Manual code entry via stdin. */
async function promptForCode(): Promise<string> {
const readline = await import('readline');
@@ -185,8 +194,11 @@ export function registerGdocsAuthCommand(program: Command): void {
// 3. Check if already authenticated
if (existsSync(tokenPath)) {
console.log(`Token already exists at ${tokenPath}`);
console.log('Delete it first 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);
}
}
const redirectUri = opts.manual