supabase-baileys
v1.0.0
Published
A lightweight TypeScript adapter that seamlessly integrates Baileys (WhatsApp Web) authentication state and end‑to‑end encryption keys with Supabase for persistent, restart‑resilient WhatsApp sessions.
Readme
Authentication with Supabase for Baileys
🔐 Persistent WhatsApp session authentication using Supabase and Baileys.
Introduction
supabase-baileys is a persistent authentication adapter for Baileys that uses Supabase as a storage backend. It allows WhatsApp multi-session states to be synced across processes or instances using a PostgreSQL + S3 backend via Supabase.
Features
- 🔄 Supports
get,set,clear, andremoveCredsoperations - 🧠 Automatically serializes and deserializes keys using
BufferJSON - 📦 Supports multiple session IDs
- ☁️ Supabase-compatible with JSONB schema
- 📁 Clear separation between
credsand key data
Installation
npm install supabase-baileysUsage
import makeWASocket from "baileys";
import { useSupabaseAuthState } from "supabase-baileys";
const { state, saveCreds } = await useSupabaseAuthState({
supabaseUrl: "https://your-project.supabase.co",
supabaseKey: "your-anon-key",
session: "your-session-id",
});
const sock = makeWASocket({
auth: state,
// ...other config
});
sock.ev.on("creds.update", saveCreds);Supabase Table Schema
Create the following table in Supabase:
create table if not exists auth (
session text not null,
id text not null,
value jsonb,
primary key (session, id)
);You can rename the table by passing tableName in the config.
Environment Variables
Alternatively, you can set Supabase credentials via .env:
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your-anon-keyThen call:
const { state, saveCreds } = await useSupabaseAuthState({
session: "your-session-id",
});API
useSupabaseAuthState(config: SupabaseConfig): Promise<SupabaseAuthState>
Parameters:
| Name | Type | Required | Description |
| ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------ |
| supabaseUrl | string | No | Your Supabase project URL. If not provided, it will be read from the SUPABASE_URL environment variable. |
| supabaseKey | string | No | Your Supabase anon/public key. If not provided, it will be read from the SUPABASE_ANON_KEY environment variable. |
| tableName | string | No | Name of the Supabase table to store credentials (default: auth). |
| session | string | Yes | A unique session ID for each WhatsApp account. |
Returns:
{
state: AuthenticationState;
saveCreds: (updatedCreds: Partial<AuthenticationCreds>) => Promise<void>;
clear: () => Promise<void>;
removeCreds: () => Promise<void>;
}License
MIT © Ahmad Rosyihuddin
