Skip to content

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

License

Notifications You must be signed in to change notification settings

rzkytmgr/baileysauth

Repository files navigation

Baileys Auth



Lightweight package multiple session and multiple authentication methods for 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
  • PostgreSQL – requires pg
  • MongoDB – requires mongodb

Example Installation

# 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

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.0 baileysauth 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,

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors 2

  •  
  •  

Languages