diff --git a/src/lib/auth/index.ts b/src/lib/auth/index.ts index 45c4a630..2f786f06 100644 --- a/src/lib/auth/index.ts +++ b/src/lib/auth/index.ts @@ -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;