Documentation Index
Fetch the complete documentation index at: https://mintlify.com/jzszdznzzl/WABotJS/llms.txt
Use this file to discover all available pages before exploring further.
Auth manages the persistence layer for WhatsApp session data. It stores Baileys authentication credentials and Signal protocol keys in a SQLite file (auth.sqlite) using WAL journal mode and NORMAL sync for durability without excessive flushing. In normal usage you never instantiate Auth directly — it is accessible as bot.auth and the Bot class calls its methods automatically at the right points in the lifecycle.
Constructor
Auth is created automatically by Bot during construction. You do not
normally call this constructor yourself. Access the instance via bot.auth.The directory in which
auth.sqlite will be created. Relative paths are
resolved to an absolute path via path.resolve() at construction time.
The directory is created automatically (including any missing parents) when
load() is called.Properties
dir
auth.sqlite is stored. Exposed as a getter.
state
{ creds, keys } object required by baileys.makeWASocket. Throws if load() has not been called yet:
state.keys object implements baileys.SignalKeyStore and performs all Signal key reads and writes through the SQLite store, batching writes inside a single BEGIN TRANSACTION / COMMIT block for atomicity.
Methods
load
- If a
'creds'row exists in the store it is deserialised and used. - If no row exists,
baileys.initAuthCreds()is called to generate a fresh identity. - The Signal key store (
state.keys) is also wired up to the SQLite backend during this call.
Bot.login() calls load() automatically before constructing the socket.
saveCreds
creds object to the SQLite store under the 'creds' key. Throws if load() has not been called:
Bot registers a listener on the Baileys creds.update event that calls saveCreds() automatically, so you should rarely need to call this directly.
drop
auth.sqlite file (and associated WAL/SHM files). Clears the in-memory creds and keys references and resets the loaded state so load() can be called again to start a fresh session.
Bot.logout() calls drop() automatically. After drop(), accessing auth.state throws until load() is called again.
dropCreds
'creds' row from the SQLite store without dropping the database file or the Signal key material. Resets the in-memory creds reference and sets the #loaded flag to false. Throws if load() has not been called:
dropCreds() when you want to force a re-authentication (new QR or OTP) while preserving other stored keys.
After calling
dropCreds(), accessing auth.state throws until load() is
called again, which will generate fresh credentials via
baileys.initAuthCreds().get
BufferJSON revival for Buffer fields). Returns undefined if the key does not exist.
The store key to retrieve. Keys are arbitrary strings; WABotJS uses
'creds'
and colon-delimited keys like 'app-state-sync-key:id' internally.set
BufferJSON replacement (so Buffer fields round-trip correctly).
The store key under which to persist the value.
Any JSON-serialisable value.
Buffer fields are serialised using the Baileys
BufferJSON.replacer so they deserialise correctly via get().del
The store key to delete.
Storage Details
SQLite store internals
SQLite store internals
The auth store is backed by
The
{dir}/auth.sqlite — a Node.js built-in
node:sqlite database (available in Node.js v24+) configured with:| PRAGMA | Value | Reason |
|---|---|---|
journal_mode | WAL | Allows concurrent reads during writes |
synchronous | NORMAL | Durable without an fsync on every write |
values table has two columns — key TEXT PRIMARY KEY and
value BLOB NOT NULL — and a secondary index on key for fast look-ups.Signal key writes (from state.keys.set) are always wrapped in an explicit
BEGIN TRANSACTION / COMMIT block, with automatic ROLLBACK on error, to
guarantee that multi-key updates are atomic.Example
The following snippet shows howbot.auth integrates into the normal bot lifecycle. You do not need to call any Auth methods yourself in typical use: