Baileys provides two methods to authenticate your WhatsApp Web client: scanning a QR code or using a pairing code. Both methods connect your bot as a secondary device to an existing WhatsApp account.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/WhiskeySockets/Baileys/llms.txt
Use this file to discover all available pages before exploring further.
Authentication methods
WhatsApp’s multi-device API allows Baileys to authenticate as a second WhatsApp client by either:- QR code: Scan a code displayed in your terminal with WhatsApp on your phone
- Pairing code: Enter a code in WhatsApp mobile settings to link without scanning
Pairing code is not the Mobile API. It’s simply an alternative method to connect WhatsApp Web without QR code scanning.
QR code authentication
The QR code method displays a scannable code in your terminal that you scan with WhatsApp on your phone.Basic QR code setup
Customizing browser appearance
You can customize how your client appears in WhatsApp’s “Linked Devices” list:- Ubuntu
- macOS
- Windows
- Custom
Pairing code authentication
The pairing code method lets users link their device by entering a code in WhatsApp settings, avoiding the need to scan a QR code.Basic pairing code setup
Check registration status
Check if credentials are already registered before requesting a pairing code:
Request pairing code
Request a pairing code using the phone number (country code + number, no special characters):
Complete pairing code example
Saving and restoring sessions
To avoid re-authenticating every time, save the authentication state to disk usinguseMultiFileAuthState.
Using multi-file auth state
The
useMultiFileAuthState function stores authentication data in a folder. For production applications, implement a custom auth state handler using a database instead.How auth state works
The authentication state contains two components:state.creds: Authentication credentials including identity keys and registration infostate.keys: Signal protocol keys for message encryption/decryption
Key state management
useMultiFileAuthState function handles this automatically, but custom implementations must be careful with key state management.
Receiving full history
By default, Baileys receives limited message history. To receive more:Authentication with custom configuration
Here’s a complete example combining authentication with common configurations:Custom auth state implementation
For production systems, implement a custom auth state using a database:The
useMultiFileAuthState implementation in src/Utils/use-multi-file-auth-state.ts serves as an excellent reference for building custom auth state handlers.Next steps
Connection management
Learn about connection lifecycle and reconnection strategies
Event handling
Handle messages, connection updates, and other events