QR code authentication is the default way to link Baileys to your WhatsApp account. Baileys emits a QR string on theDocumentation Index
Fetch the complete documentation index at: https://whiskeysockets-docs-jids-socket-config-ptbr.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
connection.update event, which you render however you like — to the terminal, to an image, or to your frontend. Open WhatsApp on your phone, navigate to Linked Devices, and scan the code to complete the link.
Basic setup
Create the socket and listen for the QR string
The QR string is delivered through the In production, send the
connection.update event. Use a library like qrcode-terminal (or qrcode for image/canvas output) to render it.qr string to your frontend and render it there instead of in the terminal.Scan the QR code
On your phone, open WhatsApp and go to Settings → Linked Devices → Link a Device. Point your camera at the rendered QR code.Once scanned, WhatsApp forcibly disconnects the socket so Baileys can reconnect with full credentials. This is expected — handle it by reconnecting on
DisconnectReason.restartRequired (see Keeping the connection alive).Customizing the browser identity and receiving full history
The browser identity Baileys presents to WhatsApp affects how your client appears in Linked Devices and how much message history is delivered on first sync. Both options are configured via the socket — see Configure the Baileys socket connection for theBrowsers presets and the syncFullHistory flag.
Keeping the connection alive
Baileys maintains a persistent WebSocket connection. If your process exits, the session is lost. Handle theconnection.update event to detect disconnections and reconnect when appropriate.