Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/authStrategies/RemoteAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class RemoteAuth extends BaseAuthStrategy {
this.clientId = clientId;
this.backupSyncIntervalMs = backupSyncIntervalMs;
this.dataPath = path.resolve(dataPath || './.wwebjs_auth/');
try {
fs.accessSync(process.cwd(), fs.constants.W_OK);
this.zipDir = process.cwd();
} catch {
console.warn(
`[RemoteAuth] (${process.cwd()}) is not writable. Falling back to dataPath (${this.dataPath}) for session zips.`,
);
this.zipDir = this.dataPath;
}
this.tempDir = `${this.dataPath}/wwebjs_temp_session_${this.clientId}`;
this.requiredDirs = [
'Default',
Expand Down Expand Up @@ -163,7 +172,7 @@ class RemoteAuth extends BaseAuthStrategy {
async extractRemoteSession() {
const pathExists = await this.isValidPath(this.userDataDir);
const compressedSessionPath = path.join(
this.dataPath,
this.zipDir,
`${this.sessionName}.zip`,
);
const sessionExists = await this.store.sessionExists({
Expand Down Expand Up @@ -205,7 +214,7 @@ class RemoteAuth extends BaseAuthStrategy {
await this.copyByRequiredDirs(userDataDefaultPath, stageDefaultPath);

const archive = archiver('zip');
const outPath = path.join(this.dataPath, `${this.sessionName}.zip`);
const outPath = path.join(this.zipDir, `${this.sessionName}.zip`);
const out = fs.createWriteStream(outPath);

await new Promise((resolve, reject) => {
Expand Down