Skip to main content
The 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.
While more efficient than single-file storage, this is not recommended for production applications. Consider implementing authentication state storage with a proper SQL or NoSQL database for production use.

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

If creds.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

The function will throw an error if a non-directory file exists at the specified folder path.