pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.08k stars 3.59k forks source link

Still get QRcode even while using remote auth #1681

Open CHR-onicles opened 2 years ago

CHR-onicles commented 2 years ago

Is there an existing issue for this?

Describe the bug

After running for about 6-7 days, it appears the session saved in mongodb expires, prompting a QRcode scan in heroku. This has happened consistently for the past 3 weeks, and sometimes scanning doesn't work; so I have to manually delete the session saved in my mongo database, rescan and wait for remote auth to save the session, after which it works perfectly, but again just for a week.

Expected behavior

QRcode should not appear, and session should restore itself continuously

Steps to Reproduce the Bug or Issue

  1. Enable remote auth
  2. Run in Heroku for a week or 2

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Linux, the bug occurs on Heroku's dynos which run Linux but my OS is Win 10 and there are no local problems Phone OS: Android Whatsapp-web.js: v1.17.1 Whatsapp web: v2.2232.8 Node.js: v18.7.0

Additional context

No response

santinot commented 11 months ago

I fix the problem installing nodejs version 18.14.2 with the npm version 9.5.0.

ps: I use remote auth with MongoDB in a Docker Container

viniciusbig commented 7 months ago

I'm facing the same issue here

It seems like a race condition when the client don't wait to the zip file to be downloades/extracted

viniciusbig commented 7 months ago

Any updates on these?

A few people tested @nkbhasker PR and it seems is working fine.

Any updates on when this wil be merged?

fpiantoni commented 7 months ago

@viniciusbig I am having the same problem in the same environment as you. Were you able to solve the issue?

Thanks!!

viniciusbig commented 7 months ago

@viniciusbig I am having the same problem in the same environment as you. Were you able to solve the issue?

Thanks!!

I've created a post-install script to replace RemoteAuth.js file with the same changes in the @nkbhasker PR

Also, yuou need to install adm-zip for this to work.

This is a temporary solution for this problem. Hopping that this PR will be merged soon

fpiantoni commented 7 months ago

@viniciusbig I am having the same problem in the same environment as you. Were you able to solve the issue? Thanks!!

I've created a post-install script to replace RemoteAuth.js file with the same changes in the @nkbhasker PR

Also, yuou need to install adm-zip for this to work.

This is a temporary solution for this problem. Hopping that this PR will be merged soon

@viniciusbig You Rock!!

4lerman commented 5 months ago

Any updates on when this wil be merged?

arpitgoyall commented 5 months ago

I solved this issue by using the same IP location of the registered phone number for whatsapp. For example my number is an Indian number and am using Indian local VPS.

aloisoinac commented 4 months ago

I've founded a solution and no more qrcode is issued to active connections on RemoteAuth strategy.

const { Client, RemoteAuth } = require('whatsapp-web.js');

// Require database
const { MongoStore } = require('wwebjs-mongo');
const mongoose = require('mongoose');

// Load the session data
mongoose.connect(process.env.MONGODB_URI).then( async () => {
    const store = new MongoStore({ mongoose: mongoose });

    // here check if sesssion exists (Replace 'MyInstanceID' by yourself instance id)
    const hasSession = await store.sessionExists({session: 'MyInstanceID'})

    // if exists so load to store resource current connection
    if(hasSession){
         await store.extract({session: 'MyInstanceID'});
    }
    const client = new Client({
        authStrategy: new RemoteAuth({
            store: store,
            // don't forget pass this property 'clientId' to multidevice connections
            clientId: 'MyInstanceID',
            backupSyncIntervalMs: 300000
        })
    });

    //if remote stored connection still alive no qrcode will be prompted.
    client.initialize();
});
rizki5411 commented 3 months ago

Saya telah menemukan solusi dan tidak ada lagi kode qr yang dikeluarkan untuk koneksi aktif pada strategi RemoteAuth.

const { Client, RemoteAuth } = require('whatsapp-web.js');

// Require database
const { MongoStore } = require('wwebjs-mongo');
const mongoose = require('mongoose');

// Load the session data
mongoose.connect(process.env.MONGODB_URI).then( async () => {
    const store = new MongoStore({ mongoose: mongoose });

    // here check if sesssion exists (Replace 'MyInstanceID' by yourself instance id)
    const hasSession = await store.sessionExists({session: 'MyInstanceID'})

    // if exists so load to store resource current connection
    if(hasSession){
         await store.extract({session: 'MyInstanceID'});
    }
    const client = new Client({
        authStrategy: new RemoteAuth({
            store: store,
            // don't forget pass this property 'clientId' to multidevice connections
            clientId: 'MyInstanceID',
            backupSyncIntervalMs: 300000
        })
    });

    //if remote stored connection still alive no qrcode will be prompted.
    client.initialize();
});

Not work with error Error: ENOENT: no such file or directory, open 'D:\01Project\03LAINNYA\apiwa\MyInstanceID.zip'

bymarcelo commented 2 months ago

I fixed it in an official/recommended way on this commit: https://github.com/pedroslopez/whatsapp-web.js/pull/3200 Encourage maintainers to approve the PR.

While the PR is not approved, you can use my fork like this:

npm install github:bymarcelo/whatsapp-web.js#fix-remote-auth-unzip

NOTE: Recommended to use node version >= 18, tested v20