useMultiFileAuthState function provides a file-based implementation of authentication state storage. It’s more efficient than single-file storage but recommended for development/bot use only.
Function Signature
Parameters
string
required
Path to the folder where authentication state files will be stored. The folder will be created if it doesn’t exist.
Returns
Returns a Promise that resolves to an object with:AuthenticationState
required
The authentication state object containing credentials and keys
() => Promise<void>
required
Function to persist credentials to disk. Call this after credential updates to save changes.
Usage Example
File Structure
The function creates the following file structure:Key Features
File Locking
The implementation uses per-file mutex locks to prevent race conditions when reading/writing files concurrently:File Name Sanitization
Special characters in key IDs are sanitized for safe file system usage:/→__:→-
Automatic Initialization
Ifcreds.json doesn’t exist, new credentials are automatically initialized using initAuthCreds().
Special Handling for App State Keys
App state sync keys are deserialized using protobuf:Error Handling
Related
- AuthenticationState - Authentication state types
- makeCacheableSignalKeyStore - Add caching to key stores