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:
@@ -124,6 +124,14 @@ export const auth = new Proxy({} as AuthInstance, {
|
|||||||
get(_target, prop) {
|
get(_target, prop) {
|
||||||
return Reflect.get(getAuth(), 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;
|
export type Session = typeof auth.$Infer.Session;
|
||||||
|
|||||||
Reference in New Issue
Block a user