Skip to content

Commit

Permalink
Merge pull request #1 from varreltantio/dev
Browse files Browse the repository at this point in the history
fix error when logout
  • Loading branch information
varreltantio authored Sep 26, 2024
2 parents bf4aed2 + 62d76fa commit 145b228
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/authStrategies/LocalAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand All @@ -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
Expand All @@ -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');
}

}
Expand Down

0 comments on commit 145b228

Please sign in to comment.