Skip to content

Baileys logout() not working with custom Redis-based auth adapter (works fine with useMultiFileAuthState) #1884

Description

@Pavan-Kumar-KN

I implemented a custom Redis-based auth adapter to replace useMultiFileAuthState in Baileys.
Everything works fine (sessions load, messages sync, etc.), but calling session.logout() doesn’t clear the session or log out from WhatsApp Web.

However, the same code works perfectly when using the built-in useMultiFileAuthState.

`
import { BufferJSON, proto, initAuthCreds } from "baileys";
import { redis } from "./redis.js";

export default async function useRedisAuthState(sessionId) {

const writeData = async (state, id) => {
    const info = JSON.stringify(state, BufferJSON.replacer);  // Store as string
    return await redis.set(`baileys:${id}`, info);
};

const readData = async (id) => {
    const data = await redis.get(`baileys:${id}`);
    if (!data) return null;
    try {
        return JSON.parse(data, BufferJSON.reviver);
    } catch (err) {
        console.error(`Error parsing data for ${id}:`, err);
        return null;
    }
};

const creds = (await readData(`${sessionId}-creds`)) || initAuthCreds();

const state = {
    creds,
    keys: {
        get: async (type, ids) => {
            const data = {};
            await Promise.all(
                ids.map(async (id) => {
                    let value = await readData(`${sessionId}-${type}-${id}`);

                    if (value && type === 'app-state-sync-key') {
                        value = proto.Message.AppStateSyncKeyData.fromObject(value);
                    }
                    data[id] = value;
                })
            );
            return data;
        },

        set: async (data) => {
            const tasks = [];
            for (const category of Object.keys(data)) {
                for (const id of Object.keys(data[category])) {
                    const value = data[category][id];
                    const key = `${sessionId}-${category}-${id}`;
                    tasks.push(value ? writeData(value, key) : redis.del(key));
                }
            }
            await Promise.all(tasks);
        }
    }
}
return {
    state,
    saveCreds: async () => await writeData(state.creds, `${sessionId}-creds`) 
};

}
`

When I call:

await sock.logout();

nothing happens.
But if I use:

const { state, saveCreds } = await useMultiFileAuthState("sessions");

Expected Behavior

Calling session.logout() should clear creds and keys from Redis (similar to how it works with file-based auth).

Actual Behavior

logout() resolves without error but the session still remains active in the device

Environment

Baileys version: latest verstion (v7)

Node version: 22x

Redis: (dev : iostash , prod : elastic cache)

Auth Adapter: Custom Redis implementation (shared above)

Additional context

Please confirm if there’s an internal Baileys API expectation for how logout() clears state so I can mirror that in my Redis adapter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions