fix(convex-plugin): await async definePayload return value#336
Conversation
The convex plugin's JWT definePayload wrapper spreads the user-supplied definePayload return value synchronously. When the user returns a Promise (as the type signature allows), spreading it yields nothing useful and all custom JWT claims are silently dropped. Only the plugin's own sessionId and iat additions survive into the JWT. Make the wrapper async and await the inner call. Sync definePayload continues to work because awaiting a non-promise is a no-op.
|
@agucova 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 JWT Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Thanks for this - we ended up fixing in #323, will be released in 0.12.0. |
Fixes #335
Summary
The convex plugin's JWT
definePayloadwrapper insrc/plugins/convex/index.tsspreads the user-supplieddefinePayloadreturn value synchronously. When a consumer returns aPromise(as the public type signature explicitly permits), the spread yields nothing and custom JWT claims are silently dropped, and only the plugin's ownsessionIdandiatsurvive into the JWT.This PR makes the wrapper
asyncandawaits the inner call.Why
The public type allows async:
The upstream
better-authjwt plugin awaitsdefinePayloadonce at the outer call site (better-auth@1.4.9,dist/plugins/jwt/sign.mjs:53), so it awaits the convex plugin's sync wrapper, not the inner user function. Result:...Promisespreads no enumerable own properties, and every custom claim is dropped. A Convex runtime warning (unawaited operation: [query]) also appears when the user's asyncdefinePayloaddoes DB work.The change (4 characters)
Synchronous
definePayloadremains correct:awaiton a non-Promise is a no-op, and the outerbetter-authcode already awaits the wrapper.Test plan
npx tsc --noEmitpassesnpm test— failure count unchanged vsmain(111 pre-existing adapter test failures on both branches; no test regressions introduced). There are no existing tests that exercisedefinePayload; happy to add one if maintainers prefer.@convex-dev/better-auth@0.10.10patched with this change): asyncdefinePayloadreturning{ roles, programs, email }now populates those claims in the JWT returned by/api/auth/tokenand/api/auth/get-session; without the patch the claims are absent.Possibly closes
May also be the root cause of #291 (First generated JWT is missing custom payload fields), see issue description for details.
Summary by CodeRabbit