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
14.62k stars 3.48k forks source link

WhatsApp web have to re-scan QR code every around 10 days #2013

Closed ccmks closed 7 months ago

ccmks commented 1 year ago

Is there an existing issue for this?

Describe the bug

I am using Windows based, and keep experience constantly that I have re-create new session and re-scan QR code to get WhatsApp re-authenticate

Expected behavior

Shouldn't have to do this all time, expected to scan the QR code and forget about it

Steps to Reproduce the Bug or Issue

Just install like usual, then scan QR code, wait around 10 days and session will disappear from http://localhost:8000/send-message and I have to re-create new session again

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Windows Phone OS: Android whatsapp-web.j version: I don't know how to find that

Additional context

No response

CSFelix commented 1 year ago

Same issue here

dannysantino commented 1 year ago

Yeah, I just realised that this seems to be the cause of this error I spent days trying to fix:

Evaluation failed: TypeError: Cannot read properties of undefined (reading 'canSend')

My session doesn't last up to ten days, though.

And now that I'm aware of the cause, I'm not so sure it's that much of an issue. I mean, don't you think it kind of poses a security risk to leave the session (from an unofficial library) running indefinitely? I could be wrong, though.

aangwie commented 1 year ago

same with me. every 10 days can't access and must be logged out first after that relogin again. I m don't use whatsapp business

fabiomello commented 1 year ago

You have to open whatsapp on phone and interact every 9 days to doesnt disconnect.

ccmks commented 1 year ago

We use whatsapp on phone daily, so this is not the case.

On Mon, Feb 20, 2023, 9:10 PM Fábio Miguel Mello @.***> wrote:

You have to open whatsapp on phone and interact every 9 days to doesnt disconnect.

— Reply to this email directly, view it on GitHub https://github.com/pedroslopez/whatsapp-web.js/issues/2013#issuecomment-1437003747, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALYEL6RSUSHILKKKEDIXWOLWYNULNANCNFSM6AAAAAAVBIIKWI . You are receiving this because you authored the thread.Message ID: @.***>

JeremiahChurch commented 1 year ago

same as #2005?

wilsinho8 commented 1 year ago

same as #2005?

Yes

ccmks commented 1 year ago

How to fix the issue?

massimorm commented 1 year ago

also i have same problem on different sessions

LaboratorySales commented 1 year ago

Sessions also fly off, customers are dissatisfied. I use LocalAuth, recently switched to RemoteAuth and regretted it, it generally works awfully. It happens that you start one account, and another one starts

hcalldee commented 1 year ago

i also get the same problem always rescaned qr every cli killed

unish7 commented 1 year ago

The same thing happened to me and I changed the authentication method to RemoteAuth, the session remained open for exactly 30 days. The 4 instances with different sessions that I had open were closed on the same day. I have not found information on how to make it stay indefinitely

ccmks commented 1 year ago

Where to change to RemoteAuth?

On Sat, Feb 25, 2023, 9:22 AM unish7 @.***> wrote:

The same thing happened to me and I changed the authentication method to RemoteAuth, the session remained open for exactly 30 days. The 4 instances with different sessions that I had open were closed on the same day. I have not found information on how to make it stay indefinitely

— Reply to this email directly, view it on GitHub https://github.com/pedroslopez/whatsapp-web.js/issues/2013#issuecomment-1444865014, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALYEL6VUJWRIFBFUPQXSJWTWZFNEVANCNFSM6AAAAAAVBIIKWI . You are receiving this because you authored the thread.Message ID: @.***>

massimorm commented 1 year ago

there are many users with the same problem. does anyone have a method to solve the problem? @pedroslopez

Olinari commented 1 year ago

+1

johnhoffmannsantos commented 1 year ago

Same Problem Here, my sessions only last 3 days and when it falls out they all fall out

Useems commented 1 year ago

Same

ccmks commented 1 year ago

Now, that I have to rescan every several minutes now. It is more and more become annoying....

Any solution on this issue? I think this is a bug or something?

Useems commented 1 year ago

Being someone with 20+ instances of whatsapp running on the same machine, I can pass on my experience:

ccmks commented 1 year ago

Hi where can I check for RemoteAuth settings? I want to see if mine is enabled or not

Message ID: @.*** com>

charles-adedotun commented 1 year ago

Being someone with 20+ instances of whatsapp running on the same machine, I can pass on my experience:

  • Graceful shutdown, destroy all running instances before destroying the process.
  • Make constant backups of your instances, I usually do it when the process is being destroyed, but I haven't tested backups at intervals (maybe it's even better and safer).
  • Avoid using current RemoteAuth solution with mongodb, it's too unstable in my humble opinion. I thought it would improve this problem, but it actually made it A LOT worse.

What method are you using to authenticate your sessions please? If RemoteAuth, what DB are you using? Thanks

brilyanilhamsadewo commented 1 year ago

Any suggestions for resolving this issue? For me, it barely lasts for two hours until I must rescan the QR code.

JeremiahChurch commented 1 year ago

Being someone with 20+ instances of whatsapp running on the same machine, I can pass on my experience:

  • Graceful shutdown, destroy all running instances before destroying the process.
  • Make constant backups of your instances, I usually do it when the process is being destroyed, but I haven't tested backups at intervals (maybe it's even better and safer).
  • Avoid using current RemoteAuth solution with mongodb, it's too unstable in my humble opinion. I thought it would improve this problem, but it actually made it A LOT worse.

@Useems could you share some examples for how you're implementing #1 & #2? That would be really helpful.

We had a similar experience with remote auth - seemed like it would help us but we also had reliability issues and for whatever reason (we didn't debug in depth) we had bounced sessions more often. Without remote auth we pretty reliably get 2 weeks before a re-auth

arielolin commented 1 year ago

Yes please!

andresrodriguezsantos44 commented 1 year ago

Esta es mi clase whatsappClient y no he tenido problemas. usando "whatsapp-web.js": "^1.21.0"

import { Service, Inject } from 'typedi'; import qrcode from 'qrcode-terminal'; import { Client, LocalAuth } from 'whatsapp-web.js'; import { ClientStatus } from './client-status'; import { handleMessage } from './messageHandler'; @Service() export class WhatsAppClient { client: Client; clientStatus: ClientStatus;

constructor(@Inject() clientStatus: ClientStatus) {
    this.client = new Client({
        authStrategy: new LocalAuth(),
    });
    this.clientStatus = clientStatus;
}

initialize() {
    console.log('Initializing whatsapp client...');
    this.client.initialize().then();
}

listenToMessages() {
    this.client.on('qr', (qr) => {
        qrcode.generate(qr, { small: true });
    });

    this.client.on('authenticated', () => {
        console.log('Client is authenticated!');
    });

    this.client.on('ready', () => {
        console.log('Client is ready!');
    });

    this.client.on('disconnected', (reason) => {
        console.log('Client is disconnected: ', reason);
        this.client.initialize().then();
    });

    this.client.on('message', async (msg) => {
        await handleMessage(msg, this.clientStatus);
    });

    process.on('unhandledRejection', (error) => {
        console.error('Unhandled Promise Rejection:', error);
    });
}

}

guy4261 commented 1 year ago

@Useems
> Graceful shutdown, destroy all running instances before destroying the process.

What's the proper way to gracefully shutdown? Client has bot logout and destroy, but I can't find any mention of the right way to gracefully shutdown.