| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…r additionalFields
|
@mrpmohiburrahman is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
Sorry, something went wrong.
Greptile SummaryThe PR adds teamMember.additionalFields support and persists data returned by beforeAddTeamMember while preserving authoritative membership fields and filtering non-returnable output.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains within the accepted scope. No blocking failure remains. Reviews (3): Last reviewed commit: "docs(organization): declare the teamMemb..." | Re-trigger Greptile |
Sorry, something went wrong.
There was a problem hiding this comment.
1 issue found across 8 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/better-auth/src/plugins/organization/organization.ts">
<violation number="1" location="packages/better-auth/src/plugins/organization/organization.ts:1037">
P1: When a `teamMember.additionalFields` entry is `required: true` without a database default, invitation acceptance and member additions that do not provide that field still insert without it, so the database rejects the row. Supply required values or defaults on every team-member insert path before registering this field as required.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Sorry, something went wrong.
|
This PR addresses the same issue as #10824. I've cross-referenced for triage, and we'll continue with whichever direction is more appropriate. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #10707.
What
beforeAddTeamMember is typed Promise<void | { data: Record<string, any> }>, the same as beforeCreateTeam and beforeUpdateTeam. It does not honour that return value. At routes/crud-team.ts the call site read the hook's result, tested it, and then did nothing with it:
The plugin has ten "data" in response sites and this was the only one with an empty body. git log -L puts its origin in bba0a42 ("feat(organization): organization life cycle hooks"), the same PR that added the working siblings — so it shipped empty rather than having been broken later. The comment describes the opposite of what the block does.
Fixing that alone is not enough to make the reporter's case work. teamMember was also the only one of the plugin's six org-owned models whose schema option omitted additionalFields — the other five all carry it. Since transformInput iterates the declared fields (packages/core/src/db/adapter/factory.ts:210) and never Object.keys(data), an undeclared key is dropped silently before it reaches any adapter. So the hook had nothing it could legally write, and the two defects are only observable together.
That gap looks like scope drift rather than a decision: additionalFields landed in 93698af, whose title names exactly the four models that existed then; teamMember arrived later with only modelName + fields, and the next model added after it (organizationRole) did ship with additionalFields.
How
computeTeamMembershipKey still hashes only [teamId, userId], so no additional field can perturb the dedup key or the unique index. Nothing under packages/core is touched.
Direction — worth a maintainer's call
I implemented the reading that the type signature promises. The honest counter-argument is that this hook's JSDoc never advertised the mutation: "You can return a data object to override the default data." appears seven times in types.ts and never for beforeAddTeamMember, and the docs example only validates and throws.
The alternative is narrowing the return type to Promise<void> and admitting the hook is validate-only. I did not take it because the TypeScript contract is unambiguous and identical to two hooks that do honour it, and because narrowing is a breaking type change for anyone returning data today — currently a silent no-op, afterwards a compile error — with no runtime benefit. If you would rather have the narrowing, say so and I will swap it; the failing test is already here either way.
Two smaller semantics I picked and would happily change:
Scope
Section 3 of the issue — that only the dedicated endpoint fires teamMember hooks — is deliberately not here. The other three insert paths (crud-org.ts, crud-members.ts, crud-invites.ts) create rows without running this hook, so hook-supplied fields are absent there. Changing that changes when hooks fire, which is an API decision rather than a bug fix. It is now stated in the docs example so nobody adopts the pattern expecting full coverage, and I am glad to follow up if you want it.
Verification
Baseline captured on main @ 64da15b before any edit; pnpm test avoided per AGENTS.md, so this is the organization plugin suite.
Zero pre-existing failures, and no test that passed in the baseline fails now. All four new tests were watched failing before the fix:
The compile-time half of the bug reproduces as TS2353 on the satisfies form and TS2769 on the organization({ … }) call form.
Changeset included (better-auth: patch).
Parts of this were written with AI assistance; I have reviewed the change and can discuss any of it.
Summary by cubic
Applies beforeAddTeamMember returned data and adds schema.teamMember.additionalFields, so member-level fields persist and round-trip like other org models. Previously the hook’s data was ignored and undeclared fields were dropped.
Migration
Written for commit 50f9c94. Summary will update on new commits.