whatsapp-web.js icon indicating copy to clipboard operation
whatsapp-web.js copied to clipboard

Still get QRcode even while using remote auth

Open CHR-onicles opened this issue 2 years ago • 61 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

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

CHR-onicles avatar Sep 01 '22 01:09 CHR-onicles

Hey! I think this problem is more related to WhatsApp sessions expiring than a bug related to RemoteAuth's implementation.

WWebjs sessions don't last forever, they usually have a limited TTL that causes them to expire eventually. It could last a month, weeks or days. When this happens, you will be prompted with the QR code to re authenticate but not because there is a bug with the library itself, but because there is not a valid session to restore anymore.

jtouris avatar Sep 06 '22 13:09 jtouris

Hey! I think this problem is more related to WhatsApp sessions expiring than a bug related to RemoteAuth's implementation.

WWebjs sessions don't last forever, they usually have a limited TTL that causes them to expire eventually. It could last a month, weeks or days. When this happens, you will be prompted with the QR code to re authenticate but not because there is a bug with the library itself, but because there is not a valid session to restore anymore.

Interesting, I see. So I still have to scan periodically :( although it might be a while before I need to scan because of Remote Auth

CHR-onicles avatar Sep 07 '22 01:09 CHR-onicles

Same issue, but it requires the qrcode scan every restart.

000ph avatar Sep 07 '22 17:09 000ph

Same issue, but it requires the qrcode scan every restart.

You are probably not using it correctly, make sure your session is being saved on your database. Please read carefully through the documentation:

Subscribing to Remote Session Saved Event: After the initial QR scan to link the device, RemoteAuth takes about 1 minute to successfully save the WhatsApp session into the remote database, therefore the ready event does not mean the session has been saved yet.

In order to listen to this event, you can now use the following:

client.on('remote_session_saved', () => {
    //Do Stuff...
}

jtouris avatar Sep 07 '22 18:09 jtouris

Hey! I think this problem is more related to WhatsApp sessions expiring than a bug related to RemoteAuth's implementation.

WWebjs sessions don't last forever, they usually have a limited TTL that causes them to expire eventually. It could last a month, weeks or days. When this happens, you will be prompted with the QR code to re authenticate but not because there is a bug with the library itself, but because there is not a valid session to restore anymore.

I am sorry but this is not true. Whatsapp web works forever without reescanning as long as you login every X days. If you hare facing that you need to re-scan QR codes frequently there is a bug in your code or whatsapp-web code (which it is because the sessions gets corrupt randomly and this is a well known reported bug)

luiscuriel avatar Sep 10 '22 20:09 luiscuriel

Hey! I think this problem is more related to WhatsApp sessions expiring than a bug related to RemoteAuth's implementation. WWebjs sessions don't last forever, they usually have a limited TTL that causes them to expire eventually. It could last a month, weeks or days. When this happens, you will be prompted with the QR code to re authenticate but not because there is a bug with the library itself, but because there is not a valid session to restore anymore.

I am sorry but this is not true. Whatsapp web works forever without reescanning as long as you login every X days. If you hare facing that you need to re-scan QR codes frequently there is a bug in your code or whatsapp-web code (which it is because the sessions gets corrupt randomly and this is a well known reported bug)

First of all, I said WWebjs sessions not WhatsApp web which of course are different in multiple ways (like WhatsApp web being official and wwebjs isn’t - lol).

Also, this “bug” of sessions expiring while using the library also happens while using LocalAuth , which is why I said this is not a RemoteAuth specific issue..

So yes, what I said is indeed true and if you want feel free to investigate further 🙂 sessions get corrupted and are no longer recoverable even if you are using LocalAuth on your local machine.

jtouris avatar Sep 11 '22 02:09 jtouris

Hey! I think this problem is more related to WhatsApp sessions expiring than a bug related to RemoteAuth's implementation. WWebjs sessions don't last forever, they usually have a limited TTL that causes them to expire eventually. It could last a month, weeks or days. When this happens, you will be prompted with the QR code to re authenticate but not because there is a bug with the library itself, but because there is not a valid session to restore anymore.

I am sorry but this is not true. Whatsapp web works forever without reescanning as long as you login every X days. If you hare facing that you need to re-scan QR codes frequently there is a bug in your code or whatsapp-web code (which it is because the sessions gets corrupt randomly and this is a well known reported bug)

First of all, I said WWebjs sessions not WhatsApp web which of course are different in multiple ways (like WhatsApp web being official and wwebjs isn’t - lol).

Also, this “bug” of sessions expiring while using the library also happens while using LocalAuth , which is why I said this is not a RemoteAuth specific issue..

So yes, what I said is indeed true and if you want feel free to investigate further 🙂 sessions get corrupted and are no longer recoverable even if you are using LocalAuth on your local machine.

Again... sorry but nope. I have been using whatsapp web libraries for javascript and nodejs for several years.

This is a BUG related to the way the session in multidevice is stored in multiple files instead of a simple auth key in a json. Whatsapp web and this library uses the same code to manage the whatsapp session through the browser. This library is just an injection of code to interact with the browser and the stores methods and variables.

The session gets lost using localauth and remoteauth because the bug is not related to where you store the files.

You can believe what you want, but if you login everyday you should NOT have to re-scan the code NEVER. When I used the json auth before the multidevice version I had a robot running for months without stop. Now I lose sessions every week.

In example, there are others libraries (in js and python) that uses the multidevice and don't suffer from this bug. Session gets never lost.

luiscuriel avatar Sep 19 '22 20:09 luiscuriel

@luiscuriel Ok lets get things clear, I think you are a bit confused with your speech talking about a different problem than the one being addressed in this particular issue.

You are talking about WhatsApp sessions in a general matter, official WhatsApp, other WhatsApp libraries or even older versions of wwebjs... I am talking about wwebjs sessions specifically for multidevice localAuth RemoteAuth mechanisms as they currently are right now.

The current situation is as is, sessions DO EXPIRE and I am not saying they should, neither arguing about it, of course they should persist longer but they don't and I personally don't know why.

I did my part by creating RemoteAuth and contributing so that sessions could be extracted into a database and persisted longer than within a file system and they actually do last longer, at least for me.

Talk is easy :) so if you say you have lots of experience of using javascript and nodejs WhatsApp libraries for several years and have a better global perspective of the problem than the rest of us, please go ahead and contribute, create a Pull Request and fix the problem for the entire community.

jtouris avatar Sep 20 '22 15:09 jtouris

Same issue, but it requires the qrcode scan every restart.

You are probably not using it correctly, make sure your session is being saved on your database. Please read carefully through the documentation:

Subscribing to Remote Session Saved Event: After the initial QR scan to link the device, RemoteAuth takes about 1 minute to successfully save the WhatsApp session into the remote database, therefore the ready event does not mean the session has been saved yet.

In order to listen to this event, you can now use the following:

client.on('remote_session_saved', () => {
    //Do Stuff...
}

I did this and saw the session on my mongodb database but it still bring the qr code on restart

osas-dev avatar Feb 13 '23 17:02 osas-dev

Still facing the issue. Anyone found the solution?

siddiquiaffan avatar Apr 25 '23 11:04 siddiquiaffan

same here ... i have the same problem ..

postix avatar Apr 27 '23 21:04 postix

same problem here

mahmouds12 avatar May 05 '23 08:05 mahmouds12

Same problem here!

wpadilla avatar May 17 '23 19:05 wpadilla

finally i used LocalAuth .... :P

postix avatar May 17 '23 21:05 postix

finally i used LocalAuth .... :P

@postix what about session backup?

siddiquiaffan avatar May 18 '23 09:05 siddiquiaffan

i just define other location of the created directory in my server ... that way i can recover every time i want ....

postix avatar May 18 '23 19:05 postix

Hi, I think I have the same problem. Below my steps in brief trying to use RemoteAuth Strategy

  1. Initialise mongodb
    ...
    import { MongoStore } from "wwebjs-mongo";
    import mongoose from "mongoose";
    
    mongoose.connect(process.env.MONGODB_URI).then(() => {
        const store = new MongoStore({ mongoose });
        ...
    });
    
  2. initialise whatsapp-web
    const waClient = new Client({
        authStrategy: new RemoteAuth({
          store,
          clientId: sessionName,
          backupSyncIntervalMs: 300000,
        }),
    });
    
    waClient.on("remote_session_saved", () => {
        ...
    });
    
    waClient.on("qr", (qr) => {
       ...
    });
    
    waClient.on("ready", () => {
       ...
    });
    
    
    waClient.initialize();
    

Everything seems to work correctly, once logged in, all the info about my session is saved to db and the RemoteAuth-clientId.zip file is also extracted correctly and put in the root of the project, but it only ever issues me the qrcode event. Shouldn't it issue the remote_session_saved event? I attach the image of the files extracted from reading from db of the RemoteAuth-clientId.zip file.

Screenshot 2023-05-23 at 12 00 19

Can someone help me? Thanks in advance

LucaTrip avatar May 23 '23 10:05 LucaTrip

@luiscuriel Ok lets get things clear, I think you are a bit confused with your speech talking about a different problem than the one being addressed in this particular issue.

You are talking about WhatsApp sessions in a general matter, official WhatsApp, other WhatsApp libraries or even older versions of wwebjs... I am talking about wwebjs sessions specifically for multidevice localAuth RemoteAuth mechanisms as they currently are right now.

The current situation is as is, sessions DO EXPIRE and I am not saying they should, neither arguing about it, of course they should persist longer but they don't and I personally don't know why.

I did my part by creating RemoteAuth and contributing so that sessions could be extracted into a database and persisted longer than within a file system and they actually do last longer, at least for me.

Talk is easy :) so if you say you have lots of experience of using javascript and nodejs WhatsApp libraries for several years and have a better global perspective of the problem than the rest of us, please go ahead and contribute, create a Pull Request and fix the problem for the entire community.

can you add some documentation how we can use session using remote auth

ChetanMotghare avatar Jun 02 '23 05:06 ChetanMotghare

try not use

puppeteer: { args: [ '--no-sandbox' ] }

ric-h avatar Jun 15 '23 21:06 ric-h

Did anyone manage to fix this with heroku and remoteauth strategy?

@LucaTrip did you actually find a solution?

@postix, you mentioned having switched back to LocalAuth, but how did you set a different folder location? Does it point to an S3 storage?

steven-tib avatar Jul 06 '23 19:07 steven-tib

The same issue, let me clarify

  1. we do save the session, thanks to remote_session_saved
  2. when we restart the server, then try to load database, then the session is not loaded its still showing QR, thats mean we failed to load, and need to scan it again for new session

agitnaeta avatar Jul 07 '23 19:07 agitnaeta

For me, it's working in Local, But when uploading on Heroku it's not working. in Heroku every time need to scan the QR code. Please help @jtourisNS @postix

s4suryapal avatar Jul 09 '23 20:07 s4suryapal

I just tested RemoteAuth along with wwebjs-mongo and it worked just fine, saved the session, and restored it successfully after a server restart. If anybody can elaborate a decent use case maybe that would help understand what is actually not working. If the session expires, well... that is a completely different topic than not even being able to restore it once.

Please consider I do not use this library (whatsapp-web.js nor wwebjs-mongo) personally so i am only aware of these problems when i test them, and everything worked fine for me today.

jtouris avatar Jul 10 '23 17:07 jtouris

The same issue, let me clarify

  1. we do save the session, thanks to remote_session_saved

  2. when we restart the server, then try to load database, then the session is not loaded its still showing QR, thats mean we failed to load, and need to scan it again for new session

Just bumping because I'm facing the same issue

p-ugulino avatar Jul 12 '23 21:07 p-ugulino

For me, it's working in Local, But when uploading on Heroku it's not working. in Heroku every time need to scan the QR code. Please help @jtourisNS @postix

Make sure to have a path for the folders .wwebjs_auth and .wwebjs_cache. If you dont have the folders in your git then it will create them in every restart and thats where the information its saved. Using local auth in heroku its not good cause it will later max out your apps memory. I was doing that but since its maxing out my memory Im trying to implement remote auth which leads me to this issue :(

AdrianGzzEsc avatar Jul 13 '23 23:07 AdrianGzzEsc

I just tested RemoteAuth along with wwebjs-mongo and it worked just fine, saved the session, and restored it successfully after a server restart. If anybody can elaborate a decent use case maybe that would help understand what is actually not working. If the session expires, well... that is a completely different topic than not even being able to restore it once.

Please consider I do not use this library (whatsapp-web.js nor wwebjs-mongo) personally so i am only aware of these problems when i test them, and everything worked fine for me today.

Im not sure what to tell you, I save the session, the 'remote_session_saved' event its triggered but after a restart instead of connecting its asking again to scan a qr. It was working before and now it doesnt

AdrianGzzEsc avatar Jul 13 '23 23:07 AdrianGzzEsc

I just tested RemoteAuth along with wwebjs-mongo and it worked just fine, saved the session, and restored it successfully after a server restart. If anybody can elaborate a decent use case maybe that would help understand what is actually not working. If the session expires, well... that is a completely different topic than not even being able to restore it once.

Please consider I do not use this library (whatsapp-web.js nor wwebjs-mongo) personally so i am only aware of these problems when i test them, and everything worked fine for me today.

@jtourisNS did it work for you when you simply force restart the dyno? Otherwise, which way did you use to restart the server?

Could you possibly share your working code as an example for us? We can then try the exact same code on our side. Thank you!

steven-tib avatar Jul 14 '23 11:07 steven-tib

@jtourisNS could you please share your code that save and restore session using RemoteAuth. Thank you

aziz1117 avatar Jul 17 '23 07:07 aziz1117

auth

jtouris avatar Jul 17 '23 15:07 jtouris

@jtourisNS appreciate your response, but when I stopped my app after ‘remote_session_saved’ message appear, and I after restart my app, still shows me qrcode next time. I wrote same code. Is there any missing code should I write to extract session from database?

aziz1117 avatar Jul 17 '23 16:07 aziz1117