An open API service indexing awesome lists of open source software.

https://github.com/rzkytmgr/baileysauth

Multiple authentication methods library for the Baileys WhatsApp bot library, supporting both SQL and NoSQL databases.
https://github.com/rzkytmgr/baileysauth

authentication auto baileys bot whatsapp whatsapp-automation whatsapp-bot

Last synced: 2 months ago
JSON representation

Multiple authentication methods library for the Baileys WhatsApp bot library, supporting both SQL and NoSQL databases.

Awesome Lists containing this project

README

          


Baileys Auth











Lightweight package multiple session and multiple authentication methods for [Baileys](https://github.com/WhiskeySockets/Baileys) whatsapp socket library. Supporting SQL and NoSQL databases.

Table of Contents

## Installation

This package relies on peer dependencies for database drivers.
Make sure to install the appropriate driver for your preferred database.
Supported databases:
- MySQL – requires [`mysql2`](https://www.npmjs.com/package/mysql2)
- PostgreSQL – requires [`pg`](https://www.npmjs.com/package/pg)
- MongoDB – requires [`mongodb`](https://www.npmjs.com/package/mongodb)

### Example Installation

```bash
# Using MySQL
npm install baileysauth mysql2

# Using PostgreSQL
npm install baileysauth pg

# Using MongoDB
npm install baileysauth mongodb
```
After packages installation, now you can import the `useBaileysAuthState` function to your code
```typescript
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:
```typescript
const { saveCreds, state } = await useBaileysAuthState(
"mysql://:@localhost:3306/mydatabase"
);
```
> [!NOTE]
> Since the release of version `v1.2.0` baileysauth has supported custom table name and session name for connection string connect method. Please check the [example](https://github.com/rzkytmgr/baileysauth/tree/master/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.
```typescript
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 – [`ConnectionOptionsBase`](https://github.com/rzkytmgr/baileysauth/blob/master/src/Types/index.ts#L29) and [`ConnectionOptions`](https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Connection.d.ts#L82-L338)
> - PostgreSQL – [`ConnectionOptionsBase`](https://github.com/rzkytmgr/baileysauth/blob/master/src/Types/index.ts#L29) and [`ClientConfig`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pg/index.d.ts#L12-L33)
> - MongoDB – [`MongoDBConnectionOptions`](https://github.com/rzkytmgr/baileysauth/blob/master/src/Types/index.ts#L42) and [`MongoClientOptions`](https://github.com/mongodb/node-mongodb-native/blob/main/src/mongo_client.ts#L141-L318)

If you are still confused, please ask by [creating an issue](https://github.com/rzkytmgr/baileysauth/issues).

## Example Usage

For usage examples, you can refer to the example directory. [Check it out!](https://github.com/rzkytmgr/baileysauth/tree/master/example)

## 🧩 Contributing
If you have any question or you have an issue when trying to use the package feel free to [create an issue](https://github.com/rzkytmgr/baileysauth/issues) or [make a pull request](https://github.com/rzkytmgr/baileysauth/pulls) to contribute.

---
Made with ❤️ by Rizky Aulia Tumangger - Copyright All Rights Reserved © 2025