Commit 4135b51
M10.2: user invite + custom org roles
Wire CRM profile names (sales_rep, sales_manager, service_agent,
marketing_user, system_admin) through Better-Auth's organization
plugin so /api/v1/auth/organization/invite-member accepts invitations
to application-defined roles instead of rejecting them with
ROLE_NOT_FOUND.
Changes:
- AuthManagerOptions / AuthPluginOptions gain additionalOrgRoles:
string[] forwarded into better-auth's organization() roles map.
- Each extra role is registered with defaultAc.newRole(memberAc.statements)
so it satisfies better-auth's access-control validator with the same
minimum capabilities as 'member'. Real RBAC enforcement remains in
ObjectStack's SecurityPlugin, which matches role names against
'permission' metadata (PermissionSets).
- Critical: re-include better-auth's built-in defaultRoles when
populating roles, because hasPermission() does
'{...options.roles || defaultRoles}' (|| then spread) and would
otherwise drop owner/admin/member entirely, breaking the inviter.
- Default requireEmailVerificationOnInvitation:false since framework
ships no mailer; operators wiring real email can opt back in.
- CLI serve.ts auto-collects roles from stack config: top-level
roles[] and permissions[] with isProfile=true. Built-in
owner/admin/member are filtered out.
Verified end-to-end with curl:
- POST invite-member role=sales_rep -> 200 sys_invitation row
- POST invite-member role=service_agent -> 200
- POST invite-member role=hacker -> 400 ROLE_NOT_FOUND: hacker
- sign-up + accept-invitation -> 200 sys_member.role=sales_rep
- sales_rep query against /api/v1/lead honours sharing rules (0 rows)
- admin retains owner privileges (no FORBIDDEN regression)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent bd5490d commit 4135b51
3 files changed
Lines changed: 105 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
674 | 705 | | |
675 | 706 | | |
676 | 707 | | |
677 | 708 | | |
678 | 709 | | |
| 710 | + | |
679 | 711 | | |
680 | 712 | | |
681 | 713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
56 | 76 | | |
57 | 77 | | |
58 | 78 | | |
| |||
248 | 268 | | |
249 | 269 | | |
250 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
251 | 309 | | |
252 | 310 | | |
253 | 311 | | |
| |||
258 | 316 | | |
259 | 317 | | |
260 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
261 | 326 | | |
262 | 327 | | |
263 | 328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
| |||
0 commit comments