`drizzleAdapter` is not handling `ne` operator

Hello, currently the convertWhereClause (L133) in drizzleAdapter is not handling the ne operator and fallsback to eq by default.

Version: 1.2.7

This cause invalid data being returned on filters. See below example:

auth.ts
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { admin } from 'better-auth/plugins';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

import * as schema from './schema';

export const auth = betterAuth({
    database: drizzleAdapter(
        drizzle({
            client: new Pool({
                connectionString: process.env.DB_CONNECTION_STRING,
            }),
            schema,
        }),
        {
            provider: 'pg',
            schema,
        },
    ),
    plugins: [admin()],
});


client.ts
import { createAuthClient } from 'better-auth/client';
import { adminClient } from 'better-auth/client/plugins';

export const client = createAuthClient({
    plugins: [adminClient()],
});


usage.ts
import { client } from './client'

const { data } = await client.admin.listUsers({
    query: {
        filterField: 'role',
        filterOperator: 'ne',
        filterValue: 'admin',
    },
});

const nonAdmins = data?.users;
// ^ This would return all admins instead.


Logs enabled debugLogs in drizzleAdapter:

[Better Auth]: [Drizzle Adapter] #2 [1/3] findMany: {
  model: 'user',
  where: [
    {
      operator: 'ne',
      connector: 'AND',
      field: 'role',
      value: 'admin'
    }
  ],
  limit: 300
}

[Better Auth]: [Drizzle Adapter] #3 [1/2] count: {
  model: 'user',
  where: [
    {
      operator: 'ne',
      connector: 'AND',
      field: 'role',
      value: 'admin'
    }
  ]
}
GitHub
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Was this page helpful?