baileysauth
v1.2.0
Published
Multiple authentication method for Baileys socket Whatsapp bot library
Maintainers
Readme
Lightweight package multiple session and multiple authentication methods for Baileys whatsapp socket library. Supporting SQL and NoSQL databases.
Installation
This package relies on peer dependencies for database drivers.
Make sure to install the appropriate driver for your preferred database.
Supported databases:
Example Installation
# Using MySQL
npm install baileysauth mysql2
# Using PostgreSQL
npm install baileysauth pg
# Using MongoDB
npm install baileysauth mongodbAfter packages installation, now you can import the useBaileysAuthState function to your code
import useBaileysAuthState from 'baileysauth';How to Use
This package provides two ways to connect to your database using a connection string or using a connection options object,
Using a Connection String
You can establish a connection by passing a valid connection string directly:
const { saveCreds, state } = await useBaileysAuthState(
"mysql://<username>:<password>@localhost:3306/mydatabase"
);[!NOTE] Since the release of version
v1.2.0baileysauth has supported custom table name and session name for connection string connect method. Please check the example directory to see how to customize it.
Using Connection Options
Alternatively, you can use an options object for more flexibility. This method allows you to specify the database driver explicitly using the dialect property and pass driver-specific options through the args property.
const { saveCreds, wipeCreds, state } = await useBaileysAuthState({
dialect: "mysql", // allowed values: mysql, pg, mongodb
database: MYSQL_DATABASE,
host: MYSQL_HOST,
user: MYSQL_USER,
password: MYSQL_PASSWORD,
port: MYSQL_PORT,
session: APP_SESSION,
table: APP_STORE,
// Driver-specific options (optional)
args: {
// For MySQL (mysql2)
connectionLimit: 10,
ssl: { rejectUnauthorized: false },
},
});[!NOTE] The args property should contain valid options specific to the selected dialect. Refer connection options below based on your dialect,
- MySQL –
ConnectionOptionsBaseandConnectionOptions- PostgreSQL –
ConnectionOptionsBaseandClientConfig- MongoDB –
MongoDBConnectionOptionsandMongoClientOptions
If you are still confused, please ask by creating an issue.
Example Usage
For usage examples, you can refer to the example directory. Check it out!
🧩 Contributing
If you have any question or you have an issue when trying to use the package feel free to create an issue or make a pull request to contribute.
Made with ❤️ by Rizky Aulia Tumangger - Copyright All Rights Reserved © 2025
