Restore interactive re-auth prompt for Google auth CLIs
This commit is contained in:
+14
-2
@@ -135,6 +135,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');
|
||||
@@ -182,8 +191,11 @@ export function registerGmailAuthCommand(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
|
||||
|
||||
Reference in New Issue
Block a user