WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
4.12k stars 1.38k forks source link

[BUG]Bug Connection Closed Immediately After Scanning QR Code #783

Open AbhishekSuresh2 opened 6 months ago

AbhishekSuresh2 commented 6 months ago

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:

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

7thRA-ONE commented 6 months ago

Same with me

sahilbrandwala commented 6 months ago

+1

ABHINAV-321 commented 6 months ago

Same issue

magicgodsir commented 6 months ago

Same issue 😭😞

Prince-luck commented 6 months ago

why

han755 commented 6 months ago

After pairing code entered one vibrate and not connecting just vibrate

meetshamee commented 6 months ago

Same issue

Rohan658 commented 6 months ago

Sir please solve auto logout issue

Thee-clipse commented 6 months ago

Same here

hiran6 commented 6 months ago

Please solve my problem

mayankagar360 commented 6 months ago

Please help @whiskeysockets-bot it is very urgent for us

EasyTech23 commented 6 months ago

It's not downloading anything except videos

zororiju commented 6 months ago

Same to me here

44102 commented 6 months ago

Same issue

badboybackagain commented 6 months ago

I am also facing the same issue.

tasinJodhpur commented 6 months ago

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.

🥹🥹🥹🥹🥹🥹🥹

tasinJodhpur commented 6 months ago

🥹💯

Tohidkhan6332 commented 6 months ago

❤️❤️

Alien-Alfa commented 6 months ago

I have the same issue but, The same code is working when on my local terminal. I scanned and got the session file the connection is still open and I am able to use it.

Please try the same code in a linux terminal rather than termux or other platforms (Just an assumption)

DAVIAMERICO242 commented 6 months ago

whatsapp has updated about 19hours ago, I think now baileysAPI is broken

Abhijithuk0007 commented 6 months ago

Same issue solve fast

sairmali commented 6 months ago

1+

enoksaju commented 6 months ago

+1

sahilbrandwala commented 6 months ago

trying to block cloud servers from accessing whatsapp web as a way to try prevent people from using libraries like Baileys. Soon all will end

Alien-Alfa commented 6 months ago

trying to block cloud servers from accessing whatsapp web as a way to try prevent people from using libraries like Baileys. Soon all will end

I think whatsapp was trying to fix a bug. The Lock Bot which used baileys in the wrong way to block user from registering. WhatsApp actually fixed the issue but at the same time this happened. Maybe it’s all connected

Alien-Alfa commented 6 months ago

For the time being we have to use local host for sessions generation until we get a proper update.

allburov commented 6 months ago

https://github.com/WhiskeySockets/Baileys/issues/779#issuecomment-2112887056

@PurpShell here we also have "conflicted", but usual restart doesn't help - the session automaticly loged out from the phone itself or show "scan QR code again" As you can notice there's additional message:

Connection closed. You are logged out.

image

allburov commented 6 months ago

btw, the similar start happening with webjs about a week ago as well, just at the same time as with Baileys - it could be related. Let me know if you need some test phone numbers or additional logs, I can give your more!

meetshamee commented 6 months ago

The previously connected is working QR is showing successfully. Sync failed

I think it is logging out due to sync problem.

Diluhch commented 6 months ago

I m also facing this issue from few days please fix this problem soon as possible

Diluhch commented 6 months ago

I m also facing this issue from few days please fix this problem soon as possible

souravkl11 commented 6 months ago

The problem is with the WhatsApp Web itself. Try to connect an Indian WhatsApp account with the official WhatsApp Web using an RDP hosted in some other region. It won't work. Lizard boy did something fishy!

Alien-Alfa commented 6 months ago

The problem is with the WhatsApp Web itself. Try to connect an Indian WhatsApp account with the official WhatsApp Web using an RDP hosted in some other region. It won't work. Lizard boy did something fishy!

Lizard boy is back with his mischief.

Alien-Alfa commented 6 months ago

btw, the similar start happening with webjs about a week ago as well, just at the same time as with Baileys - it could be related. Let me know if you need some test phone numbers or additional logs, I can give your more!

Seems like its a common issue. Most probably Whatsapp Updated its connection protocol and preference

allanlisboa commented 6 months ago

I downgraded to baileys version 6.5.0 and it solved the problem!

mayankagar360 commented 6 months ago

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

allanlisboa commented 6 months ago

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

Here the problem has been resolved

DAVIAMERICO242 commented 6 months ago

I have the same issue but If I persist scanning I'm ending up with qr code succefully connected, I use Evolution Api which is baileys based maybe it'll solve the problem.

Eu tentei fazer o downgrade da versão, mas não funcionou@allanlisboa

Alien-Alfa commented 6 months ago

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!

pandiarajanvp commented 6 months ago

Same issue. Please fix it

meetshamee commented 6 months ago

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

pra021 commented 6 months ago

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

manojsitapara commented 6 months ago

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

location means country of whatsapp phone number or same city where data center located?

pra021 commented 6 months ago

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

location means country of whatsapp phone number or same city where data center located?

Use VPN on your whatsapp installed mobile phone and set same location in mobile vpn where your web application hosted

Alien-Alfa commented 6 months ago

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

What I said was, Set up a VPN on the mobile, where the WhatsApp is installed and connect to a server, which is in the same country as the QR code hosted.

In my case, my QR was hosted on koyeb on a German server, so on my phone, I used a German server for my VPN

what happened was My WhatsApp and the QR had the same german IP because I am using the German VPN and the server is On Germany

Try this again it should work

meetshamee commented 6 months ago

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

What I said was, Set up a VPN on the mobile, where the WhatsApp is installed and connect to a server, which is in the same country as the QR code hosted.

In my case, my QR was hosted on koyeb on a German server, so on my phone, I used a German server for my VPN

what happened was My WhatsApp and the QR had the same german IP because I am using the German VPN and the server is On Germany

Try this again it should work

I tried to connect Indian cloud server (GCP), using Indian IP, But Not Working

badboybackagain commented 6 months ago

Somehow, Indian IPs are not working. I tried with German IP and installing VPN and connecting to german servers and then scanning the code. It works.

Alien-Alfa commented 6 months ago

Somehow, Indian IPs are not working. I tried with German IP and installing VPN and connecting to german servers and then scanning the code. It works.

Where was the code hosted?

meetshamee commented 6 months ago

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

sairmali commented 6 months ago

its is working fine just change your server location