Urgent help with whatsapp-web.js and mongodb.
Closed this issue · 5 comments
Hi I am Arsal. Thank you for viewing my issue.
So, the issue I am facing is that, I am using the same code on my old laptop and it's saving and retreiving the session successfully. I have recently got a new laptop for me, when trying to make this code run on this new laptop it saves the session. But when I restart the app, the app still asks for qr code.
Here is my code :
`mongoose.connect(MONGODB_URI).then(() => {
const store = new MongoStore({ mongoose: mongoose });
const WAClient = new Client({
authStrategy: new RemoteAuth({
store: store,
backupSyncIntervalMs: 300000
})
});
console.log("Starting WAClient")
WAClient.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
WAClient.on("remote_session_saved", () => {
console.log("Client session saved!");
});
});`
I am using the same code. Please let me know if you can help or suggest me anything.
Thanks for viewing my issue.
ArsalT
Hi I am Arsal. Thank you for viewing my issue.
So, the issue I am facing is that, I am using the same code on my old laptop and it's saving and retreiving the session successfully. I have recently got a new laptop for me, when trying to make this code run on this new laptop it saves the session. But when I restart the app, the app still asks for qr code.
Here is my code :
`mongoose.connect(MONGODB_URI).then(() => { const store = new MongoStore({ mongoose: mongoose }); const WAClient = new Client({ authStrategy: new RemoteAuth({ store: store, backupSyncIntervalMs: 300000 }) });
console.log("Starting WAClient") WAClient.on("qr", (qr) => { qrcode.generate(qr, { small: true }); }); WAClient.on("remote_session_saved", () => { console.log("Client session saved!"); });
});`
I am using the same code. Please let me know if you can help or suggest me anything.
Thanks for viewing my issue. ArsalT
Hi I am Arsal. Thank you for viewing my issue.
So, the issue I am facing is that, I am using the same code on my old laptop and it's saving and retreiving the session successfully. I have recently got a new laptop for me, when trying to make this code run on this new laptop it saves the session. But when I restart the app, the app still asks for qr code.
Here is my code :
`mongoose.connect(MONGODB_URI).then(() => { const store = new MongoStore({ mongoose: mongoose }); const WAClient = new Client({ authStrategy: new RemoteAuth({ store: store, backupSyncIntervalMs: 300000 }) });
console.log("Starting WAClient") WAClient.on("qr", (qr) => { qrcode.generate(qr, { small: true }); }); WAClient.on("remote_session_saved", () => { console.log("Client session saved!"); });
});`
I am using the same code. Please let me know if you can help or suggest me anything.
Thanks for viewing my issue. ArsalT
Hey I'm having the same problem but in docker. It works for me in differents local machines. Try adding these configurations to your client:
const client = new Client({
authStrategy: new RemoteAuth({
store: store,
backupSyncIntervalMs: 300000,
clientId: 'client1',
dataPath: './data/',
}),
restartOnAuthFail: true,
puppeteer: {
headless: true,
args: [
'--no-sandbox',
// other node args
],
},
});
I thought too that it could be something related to the TZ. Check if both machines are using the same TZ
Hi @kaelabbott
Thank you so much for viewing my issue. I have tried the code you gave, but it's also not working. The qr code still shows up.
How much time do you wait when you register the QR? it takes 1-5 minutes to save it.
you can use this code to verify if session was saved:
client.on('remote_session_saved', () => {
// Do Stuff...
}
Reference: https://wwebjs.dev/guide/authentication.html#example-usage
Also, are you using a local database?
Yes I know that! I use the "remote_session_saved". I wait for it to save the data, the files are visible in mongodb database, but the qr still appears.
Not completely understood what you meant by local database, but here is my MongoDB URI. Hope it helps :
mongodb://127.0.0.1:27017/
Thanks i used localauth now! It's working for me!