From 061b96fd6885df0203ccc28989e4de5943d2de20 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Tue, 17 Feb 2026 16:19:12 -0800 Subject: [PATCH] Restore interactive re-auth prompt for Google auth CLIs --- src/cli/gcal-auth.ts | 16 ++++++++++++++-- src/cli/gdocs-auth.ts | 16 ++++++++++++++-- src/cli/gdrive-auth.ts | 16 ++++++++++++++-- src/cli/gmail-auth.ts | 16 ++++++++++++++-- src/cli/gtasks-auth.ts | 16 ++++++++++++++-- 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/cli/gcal-auth.ts b/src/cli/gcal-auth.ts index 49d7bca..7efcf95 100644 --- a/src/cli/gcal-auth.ts +++ b/src/cli/gcal-auth.ts @@ -135,6 +135,15 @@ async function openBrowser(url: string): Promise { }); } +async function promptYesNo(question: string): Promise { + const readline = await import('readline'); + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true }); + const answer = await new Promise((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 { const readline = await import('readline'); @@ -182,8 +191,11 @@ export function registerGcalAuthCommand(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 diff --git a/src/cli/gdocs-auth.ts b/src/cli/gdocs-auth.ts index 26428f2..16c0434 100644 --- a/src/cli/gdocs-auth.ts +++ b/src/cli/gdocs-auth.ts @@ -138,6 +138,15 @@ async function openBrowser(url: string): Promise { }); } +async function promptYesNo(question: string): Promise { + const readline = await import('readline'); + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true }); + const answer = await new Promise((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 { 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 diff --git a/src/cli/gdrive-auth.ts b/src/cli/gdrive-auth.ts index ccd02dc..f8b13f7 100644 --- a/src/cli/gdrive-auth.ts +++ b/src/cli/gdrive-auth.ts @@ -135,6 +135,15 @@ async function openBrowser(url: string): Promise { }); } +async function promptYesNo(question: string): Promise { + const readline = await import('readline'); + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true }); + const answer = await new Promise((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 { const readline = await import('readline'); @@ -182,8 +191,11 @@ export function registerGdriveAuthCommand(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 diff --git a/src/cli/gmail-auth.ts b/src/cli/gmail-auth.ts index 567763d..f3eba83 100644 --- a/src/cli/gmail-auth.ts +++ b/src/cli/gmail-auth.ts @@ -135,6 +135,15 @@ async function openBrowser(url: string): Promise { }); } +async function promptYesNo(question: string): Promise { + const readline = await import('readline'); + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true }); + const answer = await new Promise((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 { 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 diff --git a/src/cli/gtasks-auth.ts b/src/cli/gtasks-auth.ts index 2156aaa..3a534c8 100644 --- a/src/cli/gtasks-auth.ts +++ b/src/cli/gtasks-auth.ts @@ -135,6 +135,15 @@ async function openBrowser(url: string): Promise { }); } +async function promptYesNo(question: string): Promise { + const readline = await import('readline'); + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true }); + const answer = await new Promise((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 { const readline = await import('readline'); @@ -182,8 +191,11 @@ export function registerGtasksAuthCommand(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