useMultiFileAuthState
useMultiFileAuthState is the built-in utility for file-based session persistence. It stores credentials and Signal session keys as JSON files inside a folder you specify. Calling the returned saveCreds function whenever credentials change keeps the files up to date.
useMultiFileAuthState creates the folder if it does not exist. On subsequent runs, it reads the credentials back from disk and passes them to makeWASocket via the auth option. If valid credentials are found, the socket connects without showing a QR code.
How the auth state is structured
Thestate object returned by useMultiFileAuthState conforms to the AuthenticationState type:
Saving Signal keys
useMultiFileAuthState handles this automatically — its internal keys.set implementation writes key files to disk. If you implement a custom auth store (see below), you must ensure your keys.set method persists data before returning.
Improving performance with makeCacheableSignalKeyStore
In production, every message triggers Signal key lookups that hit disk. Wrapping your key store withmakeCacheableSignalKeyStore adds an in-memory cache layer that significantly reduces I/O.
NodeCache instance. You can pass a custom CacheStore as the third argument if you need different eviction behavior.
Full reconnect example
This pattern is used in the official example script. It handles disconnections, logs out gracefully, and saves credentials on every update.Reliable JSON serialization with BufferJSON
TheuseMultiFileAuthState implementation serializes credentials using BufferJSON, a Baileys utility that correctly handles Buffer and Uint8Array values during JSON.stringify / JSON.parse. If you build a custom store and serialize auth data to JSON yourself, use BufferJSON.replacer when stringifying and BufferJSON.reviver when parsing to avoid data corruption.
Building a database-backed auth store
useMultiFileAuthState is designed for development and simple bots. For production systems, implement an AuthenticationState backed by a SQL or NoSQL database. Your implementation must satisfy the SignalKeyStore interface:
get method must return a map of the requested key IDs, and set must durably persist each entry (or delete it if the value is null) before resolving.