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

πŸ›πŸ› session does not persist using LocalAuth id πŸ›πŸ›

Open andresmv94 opened this issue 1 year ago β€’ 66 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I have been using "whatsapp-web.js" in my application for about 6 months, and yesterday the session persistence stopped working, I am using authStrategy: new LocalAuth({ clientId: user._id }), and with this When I want to use the WhatsApp channel again, I can use it without having to scan the QR again, but every time that I want to use the channel and send messages, it is making me to scan the QR and this was not happening until yesterday

Expected behavior

for first time scan the QR once, and be able to continue using whatsapp without having to scan each time I use it

Steps to Reproduce the Bug or Issue

  1. configure the server in linux to work
  2. configure whatsapp web js with authStrategy: new LocalAuth({ clientId: "some-client-id" })
  3. scan the QR and send a message
  4. reuse sending messages with the same "some-client-id"

Relevant Code

function authWhatsapp (user) => {
	console.log("init authentication");
	const client = await new Client({
      authStrategy: new LocalAuth({ clientId: user._id }), // user = {_id: "1234abc", name: "juan"}
      qrMaxRetries: 3,
      authTimeoutMs: 60000,
      puppeteer: {
        executablePath: process.env.CHROME_EXECUTABLE_PATH, // CHROME_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
        args: ["--no-sandbox", "--disable-setuid-sandbox"],
      },
    });	
	
	client.on("qr", async (qr) => {
		console.log("scan qr");
		console.log(qr);		
		
    });
	
	 client.on("ready", async () => {
		console.log("Wapp web connected");
	 });
	
}

function sendWhatsapp (user) => {
	console.log("try send messages");
	client = await new Client({
      authStrategy: new LocalAuth({ clientId: user._id }), // user = {_id: "1234abc", name: "juan"}
      authTimeoutMs: 60000,
      puppeteer: {
        executablePath: process.env.CHROME_EXECUTABLE_PATH,  // CHROME_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
        args: ["--no-sandbox", "--disable-setuid-sandbox"],
      },
    });
	
	 client.on("ready", async () => { // this is never executed 🫀
		console.log("perfect, your are authenticated, Wapp web connected");
		/*
			code to send messages...
		*/
	 });
	 
	 client.on("qr", async (qr) => {
		
		console.log("The whatsapp is asking for QR you are not authenticated");	
		console.log(qr);	
		
    });

}

for authWhatsapp function:

> init authentication
> scan qr
> [email protected]+29CIw=
> Wapp web connected

for sendWhatsapp function: 

> try send messages
> The whatsapp is asking for QR you are not authenticated
> [email protected]=

Browser Type

Google Chrome

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Ubuntu 20
Phone OS:  Android, iOS
whatsapp-web.js version [1.19.5]
WhatsApp Web version [2.2317.10]:
Node.js Version [v19.8.1]

Additional context

remember: this was not happening until yesterday, I already tried setting all the permissions to the .wwebjs_auth folder, and to all its content, but it's still the same, I also notice that in windows (no server -> my personal computer) with exactly the same configuration but using CHROME_EXECUTABLE_PATH=C:/Program Files/Google/Chrome /Application/chrome.exe, it is working correctly, any idea why?

maybe the session files are not being saved correctly in the ".wwebjs_auth" folder, but I don't really know how to look at that part

Update: in other computer with Windows is happenig the same issue so is not the OS.

andresmv94 avatar Apr 21 '23 16:04 andresmv94

I am experiencing the same problem. I have been using it for a few weeks without a problem and since yesterday it has been disconnecting me often and it does not notify me why it happens. Anyone else with this error?

benjachiban avatar Apr 21 '23 19:04 benjachiban

The whatsapp version that whatsapp-web.js mark like "working with" is = WhatsApp_Web 2.2306.7, and Now the current WhatsApp Web version is 2.2317.10. maybe something with session was changed

I am experiencing the same problem. I have been using it for a few weeks without a problem and since yesterday it has been disconnecting me often and it does not notify me why it happens. Anyone else with this error?

andresmv94 avatar Apr 21 '23 22:04 andresmv94

The whatsapp version that whatsapp-web.js mark like "working with" is = WhatsApp_Web 2.2306.7, and Now the current WhatsApp Web version is 2.2317.10. maybe something with session was changed

I am experiencing the same problem. I have been using it for a few weeks without a problem and since yesterday it has been disconnecting me often and it does not notify me why it happens. Anyone else with this error?

Pudiste encontar solucion??

benjachiban avatar Apr 23 '23 02:04 benjachiban

At first I found a solution, for now it's working. In the package.json inside node_modules/whatsapp-web... change the version of puppeteer to 18.1.0

benjachiban avatar Apr 24 '23 17:04 benjachiban

At first I found a solution, for now it's working. In the package.json inside node_modules/whatsapp-web... change the version of puppeteer to 18.1.0

Is weird because that works some times

andresmv94 avatar Apr 25 '23 15:04 andresmv94

same here

RC047 avatar Apr 26 '23 23:04 RC047

Same here

samuelfaj avatar Apr 30 '23 17:04 samuelfaj

benjachiban

I tried it, didn't work

mahmouds12 avatar May 05 '23 08:05 mahmouds12

Same problem change the version of puppeteer to 18.1.0 dont work

ch9ch9n avatar May 11 '23 15:05 ch9ch9n

@pedroslopez , some idea about this?

andresmv94 avatar May 15 '23 23:05 andresmv94

same here

Neotastisch avatar May 22 '23 14:05 Neotastisch

same here :(

akimabs avatar May 23 '23 15:05 akimabs

At first I found a solution, for now it's working. In the package.json inside node_modules/whatsapp-web... change the version of puppeteer to 18.1.0

It worked for me, update puppeteer to 20.3.0

lanstat avatar May 23 '23 22:05 lanstat

At first I found a solution, for now it's working. In the package.json inside node_modules/whatsapp-web... change the version of puppeteer to 18.1.0

It worked for me, update puppeteer to 20.3.0

Please fulls steps. I need a npm install then?

XxQuickSilverZz avatar May 24 '23 12:05 XxQuickSilverZz

My puppeteer is on version 20.3.0 but the error persists.

iAndreas avatar May 24 '23 16:05 iAndreas

@pedroslopez Maybe your help?

XxQuickSilverZz avatar May 24 '23 17:05 XxQuickSilverZz

up

Santosl2 avatar Jul 25 '23 20:07 Santosl2

UP, session persistence is super unconsistent.

Davixe7 avatar Jul 28 '23 17:07 Davixe7

same problem

longgtruong avatar Aug 02 '23 14:08 longgtruong

I had the same problem with session in another library, it seems this problem is related to some thing that Whatsapp changed. Maybe it's a false impression I've tested different libraries.

daniloavilez avatar Aug 04 '23 12:08 daniloavilez

Hi, I resolved it with permission chmod on both .wwebjs_auth and .wwebjs_cache directories

regards

leandrosantoss avatar Aug 04 '23 12:08 leandrosantoss

Hi, I resolved it with permission chmod on both .wwebjs_auth and .wwebjs_cache directories

regards chmod 777 .wwebjs_cache

still ask to scan qr code

bryanfok avatar Aug 06 '23 06:08 bryanfok

up again

Santosl2 avatar Aug 08 '23 21:08 Santosl2

still happening

mahmouds12 avatar Sep 14 '23 08:09 mahmouds12

every restart localauth not working , and send new QR, any solution to this?

amoyano avatar Dec 23 '23 15:12 amoyano

every restart localauth not working , and send new QR, any solution to this?

Have you tried the solutions mentioned above? Try updating Puppeteer to version 20.3.0 in Node_modules/whatsapp-web.js/package.json and then run 'npm update'. This worked for me.

myanpetra99 avatar Dec 29 '23 06:12 myanpetra99

This is how i fix this issue:

1/ make sure .wwebjs_auth is created after login, otherwise likely your code problem 2/ puppeteer is update 3/ make sure .wwebjs_auth is chmod 777

bryanfok avatar Jan 10 '24 12:01 bryanfok

why this is closed if actually not work?

justoverclockl avatar Jan 12 '24 17:01 justoverclockl

the solution is to wait a couple minutes after the first qr code scan to let the session be "populated" properly also as mentioned here the session is being saved in .wwebjs_auth, so make sure that folder is created properly

alechkos avatar Jan 12 '24 19:01 alechkos

I scan the qrcode, I get the qrcode, authentications is fine…if after 2 hour I restart the server I need to rescan qrcode, so it’s not a problem related to β€œwait some minutes”

justoverclockl avatar Jan 12 '24 21:01 justoverclockl