fix(auth): forward in checks through better-auth Proxy

better-auth's `toNextJsHandler` does `"handler" in auth` and falls back
to calling `auth(req)` if false. The default `has` trap looks at the
empty target and returns false, so without the override we hit the
fallback and crash because the target isn't callable. Add a `has` trap
that delegates to the real instance.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 04:09:17 +02:00
parent 1a2d2dd1e1
commit e01a87ff2e

View File

@@ -124,6 +124,14 @@ export const auth = new Proxy({} as AuthInstance, {
get(_target, prop) {
return Reflect.get(getAuth(), prop);
},
// Critical: better-auth's `toNextJsHandler` does `"handler" in auth`
// and falls back to calling `auth(req)` if false. The default `has`
// trap looks at the empty target (returning false), so without this
// we'd hit that fallback (and crash because the target isn't
// callable). Forward `in` checks to the real instance.
has(_target, prop) {
return Reflect.has(getAuth(), prop);
},
});
export type Session = typeof auth.$Infer.Session;