Registry / database / baileys-redis-auth

baileys-redis-auth

JSON →
library2.0.1jsnpmunverified

baileys-redis-auth is a specialized JavaScript/TypeScript library designed to provide robust Redis-based authentication state storage for Baileys, the popular WhatsApp Web API wrapper. Currently at version 2.0.1, this library primarily targets Baileys v7, with major releases typically coinciding with significant Baileys version updates, indicating a focused and stable release cadence. It differentiates itself by offering seamless session persistence, allowing Baileys applications to resume connections without repeated QR code scanning. Key features include flexible storage options, supporting both simple key-value pairs and the more efficient Redis Hashes (HSET) for optimized management of multiple Baileys sessions under distinct namespaces. This makes it particularly suitable for scalable applications requiring reliable session management, requiring Node.js 18+ and a running Redis server instance.

npm install baileys-redis-auth
INSTALL
IMPORT
SIG · BAILEYS-REDIS-AUTH
B
baileys-redis-auth
databasejavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useRedisAuthStateWithHSet
import { useRedisAuthStateWithHSet } from 'baileys-redis-auth'
const { useRedisAuthStateWithHSet } = require('baileys-redis-auth')
The library is ESM-only since v2.0.0; CommonJS require() is not supported.
deleteHSetKeys
import { deleteHSetKeys } from 'baileys-redis-auth'
const { deleteHSetKeys } = require('baileys-redis-auth')
Used for programmatic deletion of specific session data from Redis. Requires ESM import.

This quickstart demonstrates how to initialize Baileys with Redis authentication state using `useRedisAuthStateWithHSet`, set up basic connection event handling, and persist credentials.

import { useRedisAuthStateWithHSet } from 'baileys-redis-auth' import { RedisOptions } from 'ioredis' import makeWASocket, { DisconnectReason } from 'baileys' import { Boom } from '@hapi/boom' // Define your Redis connection options const redisOptions: RedisOptions = { host: 'localhost', port: 6379 // password: process.env.REDIS_PASSWORD ?? '', // Uncomment if your Redis has a password } // Define a unique session identifier for this Baileys session const sessionId = 'my_baileys_session_example' async function initializeBaileysWithHSet() { const { state, saveCreds, redis: authRedisInstance } = await useRedisAuthStateWithHSet( redisOptions, sessionId, console.log // Optional: pass logger for Redis connection events ) authRedisInstance.on('connect', () => console.log(`Redis (from hook) connected for session: ${sessionId}`) ) authRedisInstance.on('error', (err) => console.error(`Redis (from hook) error for session ${sessionId}:`, err) ) const sock = makeWASocket({ auth: state, printQRInTerminal: true }) sock.ev.on('creds.update', saveCreds) sock.ev.on('connection.update', (update) => { const { connection, lastDisconnect } = update if (connection === 'close') { const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut console.log('connection closed due to ', lastDisconnect?.error, ', reconnecting ', shouldReconnect) // reconnect if not logged out if (shouldReconnect) { initializeBaileysWithHSet() } } else if (connection === 'open') { console.log('opened connection') } }) // You can now use 'sock' for Baileys operations console.log('Baileys initialized with Redis HSet state for session:', sessionId) } initializeBaileysWithHSet().catch(err => console.error('Failed to initialize Baileys:', err))
Debug
Known issues
breakingVersion 2.0.0 and above are ESM-only modules. CommonJS (require()) syntax is no longer supported and will lead to runtime errors.
fix
Ensure your project is configured for ES modules (e.g., add `"type": "module"` to your `package.json`) and use `import` statements for all package imports.
affects: >=2.0.0
breakingBaileys is now a peer dependency. It must be explicitly installed in your project alongside `baileys-redis-auth`.
fix
Run `npm install baileys-redis-auth baileys` or `yarn add baileys-redis-auth baileys` to ensure both packages are installed.
affects: >=2.0.0
breakingThe official Baileys package name changed from `@whiskeysockets/baileys` to `baileys` with its v7 release. This library aligns with the new package name.
fix
Update all your Baileys import statements from `import { ... } from '@whiskeysockets/baileys'` to `import { ... } from 'baileys'`.
affects: >=2.0.0
gotchaA running Redis server instance is a prerequisite. The library will fail to connect if Redis is not available or if connection details are incorrect.
fix
Ensure your Redis server is running and accessible from your application's environment. Verify `host`, `port`, and `password` in your `redisOptions`.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax with `baileys-redis-auth` which is an ESM-only package since v2.0.0.
fix
Change your import statements to ES module syntax (e.g., `import { useRedisAuthStateWithHSet } from 'baileys-redis-auth'`) and ensure your `package.json` contains `"type": "module"`.
Error: Cannot find package 'baileys' or its corresponding type declarations.
The `baileys` package is a peer dependency but has not been installed in your project.
fix
Install Baileys using your package manager: `npm install baileys` or `yarn add baileys`.
Error: connect ECONNREFUSED <ip_address>:<port>
The application failed to connect to the Redis server, likely because the server is not running, is inaccessible, or the connection details are incorrect.
fix
Verify that your Redis server is active and reachable. Check the `host`, `port`, and `password` provided in your `redisOptions` object.
TypeError: (0 , baileys_redis_auth__WEBPACK_IMPORTED_MODULE_0__.useRedisAuthStateWithHSet) is not a function
This often occurs in bundler environments (like Webpack or Vite) when mixing CommonJS and ESM or due to incorrect build configurations for ESM modules.
fix
Ensure your bundler is correctly configured to handle ES Modules. Verify `"type": "module"` in `package.json` and check your bundler's resolution/transpilation settings for `node_modules`.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
baileysrequiredThis library acts as an authentication handler for Baileys sessions and requires Baileys itself as a peer dependency for its functionality.
Agent activity
34 hits · last 30 days
node
30
OpenAI (training)
1
Resources
baileys-redis-auth — npm install baileys-redis-auth · libregistry