Prevent crash in Convex after-hook matcher when ctx.path is undefined#256
Prevent crash in Convex after-hook matcher when ctx.path is undefined#256bitojoe wants to merge 1 commit intoget-convex:mainfrom
Conversation
|
@bitojoe is attempting to deploy a commit to the Convex Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe Convex plugin's post-middleware matcher is updated to use optional chaining when accessing the ctx.path property, changing Changes
Possibly related issues
Poem
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
This PR fixes a
TypeError: Cannot read properties of undefined (reading 'startsWith')that occurs when using the@convex-dev/better-authplugin's server-side API (e.g., callingapi.addMemberfrom a Convex mutation).The Problem
When Better Auth is invoked server-side via the API rather than an HTTP request, the
ctx.pathcan beundefined. The firstafterhook matcher in the Convex plugin was checkingctx.path.startsWith(...)without a guard, causing the entire process to crash.The Fix
Added optional chaining (
ctx.path?.startsWith) to the matcher. This ensures that:ctx.pathis missing, the matcher safely returnsfalse.Fixes #254
How to Test
@convex-dev/better-auth.api.addMember) from within a Convex mutation.TypeError: Cannot read properties of undefined.Checklist
Summary by CodeRabbit