Bug
startWebLoginWithCode() in extensions/whatsapp/src/login-qr.ts calls sock.requestPairingCode(digits) immediately after createWaSocket() returns, without waiting for the socket to reach the "connecting" state. This causes requestPairingCode to fail with "Connection Closed" every time.
Expected behavior
Per the Baileys docs, requestPairingCode must only be called after the socket emits a connection.update with connection === "connecting" or a QR event:
sock.ev.on('connection.update', async (update) => {
const {connection, lastDisconnect, qr} = update
if (connection == "connecting" || !!qr) {
const code = await sock.requestPairingCode(phoneNumber)
}
})
Current code (broken)
// login-qr.ts — startWebLoginWithCode
sock = await createWaSocket(false, Boolean(opts.verbose), { authDir: account.authDir });
// ... immediately:
const code = await sock.requestPairingCode(digits); // fails — socket not ready
Suggested fix
Wait for the QR/connecting event before calling requestPairingCode:
sock = await createWaSocket(false, Boolean(opts.verbose), {
authDir: account.authDir,
onQr: () => { /* socket is now in connecting state */ },
});
// Wait for onQr to fire
const code = await sock.requestPairingCode(digits); // now works
Compare with startWebLoginWithQr which correctly waits for the QR event before proceeding.
Environment
Bug
startWebLoginWithCode()inextensions/whatsapp/src/login-qr.tscallssock.requestPairingCode(digits)immediately aftercreateWaSocket()returns, without waiting for the socket to reach the "connecting" state. This causesrequestPairingCodeto fail with "Connection Closed" every time.Expected behavior
Per the Baileys docs,
requestPairingCodemust only be called after the socket emits aconnection.updatewithconnection === "connecting"or a QR event:Current code (broken)
Suggested fix
Wait for the QR/connecting event before calling
requestPairingCode:Compare with
startWebLoginWithQrwhich correctly waits for the QR event before proceeding.Environment
@whiskeysockets/[email protected]