Store authentication state across multiple files for efficient session management
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.
import { useMultiFileAuthState } from '@whiskeysockets/baileys'const { state, saveCreds } = await useMultiFileAuthState('./auth_info')// Use the state when creating a socket connectionconst sock = makeWASocket({ auth: state, // ... other options})// Listen for credential updates and save themsock.ev.on('creds.update', saveCreds)
The function will throw an error if a non-directory file exists at the specified folder path.
if (folderInfo && !folderInfo.isDirectory()) { throw new Error( `found something that is not a directory at ${folder}, ` + `either delete it or specify a different location` )}