From b4bf9fb818ee31df240f535ddaeb56541fe21a44 Mon Sep 17 00:00:00 2001 From: ephraimduncan Date: Mon, 1 Jun 2026 09:45:54 +0000 Subject: [PATCH 1/2] fix: add has trap to lazy auth proxy so auth routes resolve handler The lazy `auth` Proxy only trapped `get`, leaving `has` to forward to its empty target. better-auth's `toNextJsHandler` checks `"handler" in auth` per request; that returned false, so it fell through to calling `auth(request)`, which isn't callable. Result: every /api/auth/* POST threw "TypeError: ... is not a function" in production (e.g. sign-in/social). Add a `has` trap forwarding to the real instance. Stays build-time safe: the check only runs inside toNextJsHandler's per-request closure, never at module load, so env-validation decoupling is preserved. --- packages/auth/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/auth/index.ts b/packages/auth/index.ts index 5fa108f..fc5d42b 100644 --- a/packages/auth/index.ts +++ b/packages/auth/index.ts @@ -81,6 +81,9 @@ export const auth = new Proxy({} as Auth, { const value = Reflect.get(authClient, property); return typeof value === 'function' ? value.bind(authClient) : value; }, + has(_target, property) { + return Reflect.has(getAuth(), property); + }, }); export type Session = typeof auth.$Infer.Session; From 6b8331f5f3f0791ff28328b0f7b789f10bda655b Mon Sep 17 00:00:00 2001 From: ephraimduncan Date: Mon, 1 Jun 2026 10:01:47 +0000 Subject: [PATCH 2/2] fix: type lazy proxy get-traps to satisfy no-unsafe lint The get-traps assigned `Reflect.get(...)`'s `any` return, tripping @typescript-eslint/no-unsafe-{assignment,return,call,member-access} (12 errors, pre-existing red on main since the proxies landed). Annotate the forwarded value as `unknown` and cast on the function branch so binding is type-checked. Runtime behavior is unchanged. --- packages/auth/index.ts | 6 ++++-- packages/db/index.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/auth/index.ts b/packages/auth/index.ts index fc5d42b..8fda016 100644 --- a/packages/auth/index.ts +++ b/packages/auth/index.ts @@ -78,8 +78,10 @@ const getAuth = () => { export const auth = new Proxy({} as Auth, { get(_target, property) { const authClient = getAuth(); - const value = Reflect.get(authClient, property); - return typeof value === 'function' ? value.bind(authClient) : value; + const value: unknown = Reflect.get(authClient, property); + return typeof value === 'function' + ? (value as (...args: unknown[]) => unknown).bind(authClient) + : value; }, has(_target, property) { return Reflect.has(getAuth(), property); diff --git a/packages/db/index.ts b/packages/db/index.ts index af304f0..b8cf638 100644 --- a/packages/db/index.ts +++ b/packages/db/index.ts @@ -30,8 +30,10 @@ const getQueryClient = () => { export const queryClient = new Proxy({} as Client, { get(_target, property) { const client = getQueryClient(); - const value = Reflect.get(client, property); - return typeof value === 'function' ? value.bind(client) : value; + const value: unknown = Reflect.get(client, property); + return typeof value === 'function' + ? (value as (...args: unknown[]) => unknown).bind(client) + : value; }, set(_target, property, value) { return Reflect.set(getQueryClient(), property, value); @@ -55,8 +57,10 @@ const getDb = () => { export const db = new Proxy({} as Database, { get(_target, property) { const database = getDb(); - const value = Reflect.get(database, property); - return typeof value === 'function' ? value.bind(database) : value; + const value: unknown = Reflect.get(database, property); + return typeof value === 'function' + ? (value as (...args: unknown[]) => unknown).bind(database) + : value; }, set(_target, property, value) { return Reflect.set(getDb(), property, value);