whatsapp-web.js
whatsapp-web.js copied to clipboard
Still get QRcode even while using remote auth
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
- Enable remote auth
- 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
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.
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
Same issue, but it requires the qrcode scan every restart.
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...
}
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)
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.
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 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.
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
Still facing the issue. Anyone found the solution?
same here ... i have the same problem ..
same problem here
Same problem here!
finally i used LocalAuth .... :P
finally i used LocalAuth .... :P
@postix what about session backup?
i just define other location of the created directory in my server ... that way i can recover every time i want ....
Hi, I think I have the same problem. Below my steps in brief trying to use RemoteAuth Strategy
- Initialise mongodb
... import { MongoStore } from "wwebjs-mongo"; import mongoose from "mongoose"; mongoose.connect(process.env.MONGODB_URI).then(() => { const store = new MongoStore({ mongoose }); ... });
- 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.
Can someone help me? Thanks in advance
@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
try not use
puppeteer: { args: [ '--no-sandbox' ] }
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?
The same issue, let me clarify
- we do save the session, thanks to
remote_session_saved
- 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
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
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.
The same issue, let me clarify
we do save the session, thanks to
remote_session_saved
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
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 :(
I just tested
RemoteAuth
along withwwebjs-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
norwwebjs-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
I just tested
RemoteAuth
along withwwebjs-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
norwwebjs-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!
@jtourisNS could you please share your code that save and restore session using RemoteAuth. Thank you
@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?