Skip to content

Conversation

@Adi1231234
Copy link
Contributor

@Adi1231234 Adi1231234 commented Sep 1, 2025

PR Details

Refactor and harden RemoteAuth backup/restore flow to improve reliability, ensure deterministic cleanup, and avoid persisting unnecessary metadata.

Description

  • Refactored storeRemoteSession

    • Early return when user-data directory is missing.
    • Wrapped compression and remote save in try/finally; centralized cleanup with Promise.allSettled.
    • Emit REMOTE_SESSION_SAVED only after a successful store.save.
  • Improved compressSession

    • Added staging directory (tempDir/Default) prepared with fs.emptyDir.
    • New helper copyByRequiredDirs(from, to) to copy only required subfolders (Default, IndexedDB, Local Storage).
    • Simplified archiving with a single Promise and proper stream error handling.
    • Return the zip output path so callers can reliably clean it up.
  • Code cleanup

    • Removed deleteMetadata (selective copy makes it unnecessary).
    • Centralized deletion of temp directory and zip file in one place.
    • Fixed export typo to module.exports = RemoteAuth.

Related Issue(s)

closes #3724

Motivation and Context

  • More robust: cleanup always runs even on failures.
  • Safer: only required data is copied, reducing chances of leaking or persisting irrelevant metadata.
  • Simpler and easier to maintain: clear responsibilities between compress, save, and cleanup.
  • More efficient disk usage: less copying and deleting.
  • Correct event ordering: emit after successful persistence.

How Has This Been Tested

  • Login without prior session: verified a valid profile is created.
  • afterAuthReady: verified first backup runs and REMOTE_SESSION_SAVED is emitted.
  • Forced save error (e.g., write-permission restriction): verified cleanup still executes.
  • Confirmed temp directory and zip file are always removed after backup.

Environment

  • Machine OS: Windows
  • Phone OS: Not tested
  • Library Version: 1.33.1
  • Node Version: v20.19.4

Types of changes

  • Dependency change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (index.d.ts).
  • I have updated the usage example accordingly (example.js).
@Adi1231234
Copy link
Contributor Author

Adi1231234 commented Sep 17, 2025

Hi @alechkos @pedroslopez @wwebjs-bot @purpshell @shirser121
when you have a moment I’d really appreciate your review on this PR.
It’s a small change, but it made a noticeable improvement.
If you’d prefer a different approach, I’d be more than happy to adjust it based on your feedback.
Thanks for your time!

@IlayBacil1999
Copy link

Looks great. I was running into this exact issue, and this PR completely fixes it for me

@idolaman
Copy link

idolaman commented Nov 9, 2025

That's great solution for it. Works for me

@yair-cohen0
Copy link

yair-cohen0 commented Nov 9, 2025

Thanks that helped me alot!!

@purpshell purpshell requested a review from tuyuribr November 20, 2025 11:26
@Adi1231234
Copy link
Contributor Author

@tuyuribr can you help please? 🙏

@Adi1231234
Copy link
Contributor Author

@BenyFilho can you check this out please? 🙏

@BenyFilho
Copy link
Collaborator

@BenyFilho can you check this out please? 🙏

I don’t have any say in that. I’m just a user like you. Unfortunately, no one is taking care of it.

@Adi1231234
Copy link
Contributor Author

@tuyuribr @shirser121 @aliyss @purpshell @codebossdev
Can someone check this PR? 🙏🙏🙏
It significantly improves the mechanism and is not too complicated.

@Adi1231234
Copy link
Contributor Author

@purpshell Thanks!
@tuyuribr Can you check this out?🙏🙏

Fixed ESLint indentation errors (lines 105-127) by changing from
2-space to 4-space indentation to match project standards.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@adrianliz
Copy link

adrianliz commented Jan 8, 2026

@tuyuribr Please can you review this?
It would be so helpful
Thanks

@pedroslopez 🙏

@adrianliz
Copy link

@pedroslopez @tuyuribr
Could you please take a look at the PR?
Thanks!

@BenyFilho BenyFilho added help wanted Extra attention is needed waiting for a response Waiting for a response from the author of an issue or a PR labels Jan 30, 2026
@BenyFilho
Copy link
Collaborator

@Adi1231234 review your PR with the recent changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed waiting for a response Waiting for a response from the author of an issue or a PR

7 participants