From 295c3e620dae7503c52cca7b9262264d70b26c7f Mon Sep 17 00:00:00 2001 From: gavrielc Date: Sat, 31 Jan 2026 18:57:15 +0200 Subject: [PATCH] Fix: exit gracefully when auth needed in daemon mode If WhatsApp authentication is required but the process is running non-interactively (as a launchd daemon), exit with an error instead of showing a QR code that nobody will see. Co-Authored-By: Claude Opus 4.5 --- src/index.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index fc42578..4b01093 100644 --- a/src/index.ts +++ b/src/index.ts @@ -356,9 +356,16 @@ async function connectWhatsApp(): Promise { const { connection, lastDisconnect, qr } = update; if (qr) { - console.log('\nScan this QR code with WhatsApp:\n'); - qrcode.generate(qr, { small: true }); - console.log('\nWaiting for scan...\n'); + // Only show QR if running interactively (not as a background daemon) + if (process.stdout.isTTY) { + console.log('\nScan this QR code with WhatsApp:\n'); + qrcode.generate(qr, { small: true }); + console.log('\nWaiting for scan...\n'); + } else { + logger.error('WhatsApp authentication required but running non-interactively.'); + logger.error('Run "npm run dev" manually to scan the QR code, then restart the service.'); + process.exit(1); + } } if (connection === 'close') {