Baileys: [BUG]Bug Connection Closed Immediately After Scanning QR Code

Description: When attempting to log in to WhatsApp using Baileys library, the connection is immediately closed after scanning the QR code. This issue prevents new connections from being established, while old connections continue to work as expected.

Sample Code Of Qr:

import makeWASocket, { DisconnectReason, BufferJSON, useMultiFileAuthState } from '@whiskeysockets/baileys'
import { Boom } from '@hapi/boom'

async function connectToWhatsApp () {
    const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')

    const sock = makeWASocket({
        auth: state,
        printQRInTerminal: true, 
    });

    sock.ev.on('creds.update', saveCreds)

    sock.ev.on('connection.update', (update) => {
        const { connection, lastDisconnect } = update
        if (connection === 'close') {
            const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
            console.log('Connection closed due to', lastDisconnect?.error, ', reconnecting', shouldReconnect)
            if (shouldReconnect) {
                connectToWhatsApp() // Reconnect if necessary
            }
        } else if (connection === 'open') {
            console.log('Opened connection')
        }
    });

    sock.ev.on('messages.upsert', m => {
        console.log("Message Received: " + m.messages[0].key.remoteJid);
    });

}

connectToWhatsApp()

Error Message: Connection closed. You are logged out. 3|WaunofficialNode3007 | updateInstanceStatus 339 | Changing instance status to :: false 3|WaunofficialNode3007 | startsock :: connection update { 3|WaunofficialNode3007 | connection: ‘close’, 3|WaunofficialNode3007 | lastDisconnect: { 3|WaunofficialNode3007 | error: Error: Stream Errored (conflict) 3|WaunofficialNode3007 | at WebSocket. (/opt/NodeJs/WAMultiDevice3007/whatsappmultipledevice/Baileys-master/src/Socket/socket.ts:514:7) 3|WaunofficialNode3007 | at WebSocket.emit (events.js:400:28) 3|WaunofficialNode3007 | at WebSocket.emit (domain.js:475:12) 3|WaunofficialNode3007 | at /opt/NodeJs/WAMultiDevice3007/whatsappmultipledevice/Baileys-master/src/Socket/socket.ts:278:23 3|WaunofficialNode3007 | at Object.decodeFrame (/opt/NodeJs/WAMultiDevice3007/whatsappmultipledevice/Baileys-master/src/Utils/noise-handler.ts:164:5)

To Reproduce:

  1. Create a new connection.
  2. Scan the QR code.
  3. Observe the connection failure.

Expected Behavior: After scanning the QR code, the connection should be established successfully, allowing communication with WhatsApp.

Environment:

  • Running on a local machine.
  • connectOptions:
    • makeWASocket({ auth: state, printQRInTerminal: true, });
  • No multiple clients on the same IP.
  • Not using a proxy.

Additional Context: This issue affects new connections only, while existing connections continue to function properly. Any insights or workaround solutions would be appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 82 (3 by maintainers)

Most upvoted comments

Temporary Solution

Hey everyone,

I’ve found a temporary fix for the issue we’re facing. Since my QR code is hosted on Koyeb’s free account, it runs on a German server, thus it should have a German IP address. I experimented by connecting through a German VPN, and and it managed to connect successfully. I tried it several time and it works! In my case it won’t work with any other VPN than German

So, my theory is to try connecting through a VPN located in the same region as the server. This might just do the trick.

I’m currently using “@whiskeysockets/baileys” version 6.6.0.

Feel free to share your insights!

Temporary Solution

Hey everyone,

I’ve found a temporary fix for the issue we’re facing. Since my QR code is hosted on Koyeb’s free account, it runs on a German server, thus it should have a German IP address. I experimented by connecting through a German VPN, and and it managed to connect successfully. I tried it several time and it works! In my case it won’t work with any other VPN than German

So, my theory is to try connecting through a VPN located in the same region as the server. This might just do the trick.

I’m currently using “@whiskeysockets/baileys” version 6.6.0.

Feel free to share your insights!

Not Working

Same with me

I have tried downgrading the version but it did not work @allanlisboa

Here the problem has been resolved

After pairing code entered one vibrate and not connecting just vibrate

On waziper script still working perfectly anyone know which library they are using?

I think its 6.6

I tried to connect German cloud server (Contabo), using German VPN, its Working. Thanks @Alien-Alfa

Temporary Solution

Hey everyone,

I’ve found a temporary fix for the issue we’re facing. Since my QR code is hosted on Koyeb’s free account, it runs on a German server, thus it should have a German IP address. I experimented by connecting through a German VPN, and and it managed to connect successfully. I tried it several time and it works! In my case it won’t work with any other VPN than German

So, my theory is to try connecting through a VPN located in the same region as the server. This might just do the trick.

I’m currently using “@whiskeysockets/baileys” version 6.6.0.

Feel free to share your insights!

Used same location VPN on mobile Working perfectly

❤️❤️

Same issue 😭😞

Same issue