0xShumai
BABetter Auth
•Created by 0xShumai on 4/21/2025 in #bug-reports
`drizzleAdapter` is not handling `ne` operator
Hello, currently the
client.ts
usage.ts
Logs enabled
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()],
});
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()],
});
import { createAuthClient } from 'better-auth/client';
import { adminClient } from 'better-auth/client/plugins';
export const client = createAuthClient({
plugins: [adminClient()],
});
import { createAuthClient } from 'better-auth/client';
import { adminClient } from 'better-auth/client/plugins';
export const client = createAuthClient({
plugins: [adminClient()],
});
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.
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.
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'
}
]
}
[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'
}
]
}
1 replies