Skip to content

Commit 68bd764

Browse files
fix: add has trap to lazy auth proxy so auth routes resolve handler (#139)
* 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. * 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.
1 parent 7afa7e0 commit 68bd764

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

packages/auth/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ const getAuth = () => {
7878
export const auth = new Proxy({} as Auth, {
7979
get(_target, property) {
8080
const authClient = getAuth();
81-
const value = Reflect.get(authClient, property);
82-
return typeof value === 'function' ? value.bind(authClient) : value;
81+
const value: unknown = Reflect.get(authClient, property);
82+
return typeof value === 'function'
83+
? (value as (...args: unknown[]) => unknown).bind(authClient)
84+
: value;
85+
},
86+
has(_target, property) {
87+
return Reflect.has(getAuth(), property);
8388
},
8489
});
8590

packages/db/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ const getQueryClient = () => {
3030
export const queryClient = new Proxy({} as Client, {
3131
get(_target, property) {
3232
const client = getQueryClient();
33-
const value = Reflect.get(client, property);
34-
return typeof value === 'function' ? value.bind(client) : value;
33+
const value: unknown = Reflect.get(client, property);
34+
return typeof value === 'function'
35+
? (value as (...args: unknown[]) => unknown).bind(client)
36+
: value;
3537
},
3638
set(_target, property, value) {
3739
return Reflect.set(getQueryClient(), property, value);
@@ -55,8 +57,10 @@ const getDb = () => {
5557
export const db = new Proxy({} as Database, {
5658
get(_target, property) {
5759
const database = getDb();
58-
const value = Reflect.get(database, property);
59-
return typeof value === 'function' ? value.bind(database) : value;
60+
const value: unknown = Reflect.get(database, property);
61+
return typeof value === 'function'
62+
? (value as (...args: unknown[]) => unknown).bind(database)
63+
: value;
6064
},
6165
set(_target, property, value) {
6266
return Reflect.set(getDb(), property, value);

0 commit comments

Comments
 (0)