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 <noreply@anthropic.com>
This commit is contained in:
gavrielc
2026-01-31 18:57:15 +02:00
parent c17823a732
commit 295c3e620d

View File

@@ -356,9 +356,16 @@ async function connectWhatsApp(): Promise<void> {
const { connection, lastDisconnect, qr } = update;
if (qr) {
// 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') {