remote auth is not working in whatsapp-web.js
Opened this issue · 0 comments
alefcer0 commented
I´m trying to save sessions in mongo using RemoteAuth but the sessions are saving like if I were using LocalAuth.
Here is a basic code that I'm trying to run:
require('dotenv').config();
const { Client, RemoteAuth } = require('whatsapp-web.js');
const { MongoStore } = require('wwebjs-mongo');
const mongoose = require('mongoose');
const qrcodeTerminal = require('qrcode-terminal');
// Conectar a la base de datos MongoDB
mongoose.connect(process.env.MONGODB_URI).then(() => {
console.log('Conectado a MongoDB');
// Crear el almacenamiento en MongoDB
const store = new MongoStore({ mongoose: mongoose });
// Crear el cliente de WhatsApp con autenticación remota
const client = new Client({
authStrategy: new RemoteAuth({
store: store,
backupSyncIntervalMs: 300000 // 5 minutos
})
});
// Escuchar el evento 'qr' para generar el código QR en la terminal
client.on('qr', (qr) => {
console.log('Escanea este código QR para iniciar sesión:');
qrcodeTerminal.generate(qr, { small: true }); // Mostrar el QR en la terminal
});
// Escuchar cuando el cliente esté listo
client.on('ready', () => {
console.log('Cliente listo!');
});
// Iniciar el cliente de WhatsApp
client.initialize();
}).catch(err => {
console.error('Error al conectar a MongoDB', err);
});