Incompatibility with better-auth: @neondatabase/serverless requires tagged-template syntax, breaking drizzle-orm/neon-http integration
Hi Neon team,
We tried to integrate the better-auth service to handle auth in our api, but we keep hitting this runtime error introduced to the 1.0.0 update of @neondatabase/serverless package. We are using drizzle-orm/neon-http as the orm for our database
Since betterAuth doesn't use Tagged-template composability in order to run their queries, whenever I hit an auth endpoint we receive the following error from the Neon client library:
[wrangler:inf] OPTIONS /api/auth/sign-up/email 204 No Content (10ms)
✘ [ERROR] # SERVER_ERROR: Error: This function can now be called only as a tagged-template function: sql`SELECT ${value}`, not sql("SELECT $1", [value], options). For a conventional function call with value placeholders ($1, $2, etc.), use sql.query("SELECT $1", [value], options).
at templateFn
(file:///Users/.../JMS/IMM/node_modules/.pnpm/@[email protected]/node_modules/@neondatabase/serverless/index.mjs:1276:25)
at NeonHttpPreparedQuery.execute
(file:///Users/.../JMS/IMM/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]._eb019f29a71876f37cfe38449d23157e/node_modules/src/neon-http/session.ts:68:24)
at null.<anonymous>
(file:///Users/.../JMS/IMM/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]._eb019f29a71876f37cfe38449d23157e/node_modules/src/pg-core/query-builders/select.ts:1003:27)
at Object.startActiveSpan
(file:///Users/.../JMS/IMM/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]._eb019f29a71876f37cfe38449d23157e/node_modules/src/tracing.ts:27:11)
at PgSelectBase.execute
(file:///Users/.../JMS/IMM/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]._eb019f29a71876f37cfe38449d23157e/node_modules/src/pg-core/query-builders/select.ts:1002:17)
at PgSelectBase.then
(file:///Users/.../JMS/IMM/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]._eb019f29a71876f37cfe38449d23157e/node_modules/src/query-promise.ts:31:15)
[wrangler:inf] POST /api/auth/sign-up/email 500 Internal Server Error (17ms)
Steps to reproduce
1 - initialize db connection
import { betterAuth } from "better-auth"
import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import * as authSchema from "@/db/pg/schema/auth";
const sql = neon(connectionString);
const db = drizzle({ client: sql, schema: authSchema });
export const auth = betterAuth({
emailAndPassword: {
enabled: true
},
database: drizzleAdapter(db, {
provider: "pg",
schema: authSchema,
usePlural: true,
})
});
Expected result
We expected @neon/serverless to be able to support the way pg driver and better-auth are calling the tagged-template function, since libraries who supports neon does not support Tagged-template composability since it's relatively new.
Environment / Packages involved
- [1.0.1] @neondatabase/serverless
- [0.38.4] drizzle-orm/neon-http
- [1.3.4] better-auth/adapters/drizzle
Here is the response I got from the better-auth team
https://github.com/better-auth/better-auth/issues/3678#issue-3270973362
https://github.com/better-auth/better-auth/issues/3678#issuecomment-3145245111
Might not help, but: I moved from Drizzle to Kysely so I can use Neon's driver with Better Auth. That combination works fine.