From 62d76fa6635dbcd5881786296ab721249afbd547 Mon Sep 17 00:00:00 2001 From: varreltantio Date: Thu, 26 Sep 2024 10:35:15 +0700 Subject: [PATCH] fix error when logout --- src/authStrategies/LocalAuth.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/authStrategies/LocalAuth.js b/src/authStrategies/LocalAuth.js index 543a6b9ba1..0af1e43bba 100644 --- a/src/authStrategies/LocalAuth.js +++ b/src/authStrategies/LocalAuth.js @@ -11,11 +11,11 @@ const BaseAuthStrategy = require('./BaseAuthStrategy'); * @param {string} options.dataPath - Change the default path for saving session files, default is: "./.wwebjs_auth/" */ class LocalAuth extends BaseAuthStrategy { - constructor({ clientId, dataPath }={}) { + constructor({ clientId, dataPath } = {}) { super(); const idRegex = /^[-_\w]+$/i; - if(clientId && !idRegex.test(clientId)) { + if (clientId && !idRegex.test(clientId)) { throw new Error('Invalid clientId. Only alphanumeric characters, underscores and hyphens are allowed.'); } @@ -28,12 +28,12 @@ class LocalAuth extends BaseAuthStrategy { const sessionDirName = this.clientId ? `session-${this.clientId}` : 'session'; const dirPath = path.join(this.dataPath, sessionDirName); - if(puppeteerOpts.userDataDir && puppeteerOpts.userDataDir !== dirPath) { + if (puppeteerOpts.userDataDir && puppeteerOpts.userDataDir !== dirPath) { throw new Error('LocalAuth is not compatible with a user-supplied userDataDir.'); } fs.mkdirSync(dirPath, { recursive: true }); - + this.client.options.puppeteer = { ...puppeteerOpts, userDataDir: dirPath @@ -43,12 +43,7 @@ class LocalAuth extends BaseAuthStrategy { } async logout() { - if (this.userDataDir) { - await fs.promises.rm(this.userDataDir, { recursive: true, force: true }) - .catch((e) => { - throw new Error(e); - }); - } + console.log('Client logout'); } }