Commit 29ef1e1
fix(plugin-auth): open the SCIM request scope at handleRequest so SCIM provisioning runs inside one engine transaction (#14624)
The adapter's `transaction` config opens a real `engine.transaction()` only
while `inScimRequestScope()` reads true. The scope was stamped with
`AsyncLocalStorage.enterWith` inside the `verifyBearerToken` callback handed
to `@better-auth/scim`, and on 1.7.2 the store never reached the writes: an
`enterWith` marks only the async resource it runs in and its descendants,
and the vendor resumes the endpoint handler from a continuation captured
before the verifier ran. Measured: zero `engine.transaction` and zero
`driver.beginTransaction` calls across POST /Users + PATCH /Users/{id},
`inScimRequestScope()` false inside every sys_user / sys_scim_user write.
`AuthManager.handleRequest` now opens the scope with `run(...)` around every
request whose better-auth endpoint path is under `/scim/v2` — the same seam
the actor-attribution scope and the subject-erasure transaction use, and
exactly as narrow as before: non-SCIM flows keep their sequential posture.
A refused last-administrator deactivation now rolls the vendor's own
`scimUser.active = false` write back; the #14360 suite's face (c) pin on that
residual is flipped from `false` to `true` deliberately. A new runtime pin
(`scim-transaction-scope.test.ts`) observes each SCIM mutation calling
`engine.transaction`, a failed provisioning leaving no partial identity, and
sign-up/sign-in opening zero transactions.
Claude-Session: https://claude.ai/code/session_01AUF1NoViznQK32gqpK8wS8
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8a8e541 commit 29ef1e1
7 files changed
Lines changed: 523 additions & 34 deletions
File tree
- .changeset
- packages/plugins/plugin-auth/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
923 | 923 | | |
924 | 924 | | |
925 | 925 | | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
926 | 942 | | |
927 | 943 | | |
928 | 944 | | |
| |||
3266 | 3282 | | |
3267 | 3283 | | |
3268 | 3284 | | |
3269 | | - | |
| 3285 | + | |
3270 | 3286 | | |
3271 | 3287 | | |
3272 | 3288 | | |
3273 | 3289 | | |
3274 | 3290 | | |
3275 | | - | |
3276 | | - | |
3277 | | - | |
3278 | | - | |
3279 | | - | |
| 3291 | + | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
| 3297 | + | |
| 3298 | + | |
| 3299 | + | |
| 3300 | + | |
3280 | 3301 | | |
3281 | 3302 | | |
3282 | 3303 | | |
| |||
4740 | 4761 | | |
4741 | 4762 | | |
4742 | 4763 | | |
| 4764 | + | |
| 4765 | + | |
| 4766 | + | |
| 4767 | + | |
| 4768 | + | |
| 4769 | + | |
| 4770 | + | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
| 4775 | + | |
| 4776 | + | |
| 4777 | + | |
| 4778 | + | |
| 4779 | + | |
| 4780 | + | |
| 4781 | + | |
| 4782 | + | |
| 4783 | + | |
| 4784 | + | |
| 4785 | + | |
4743 | 4786 | | |
4744 | 4787 | | |
4745 | | - | |
4746 | | - | |
| 4788 | + | |
| 4789 | + | |
4747 | 4790 | | |
4748 | 4791 | | |
4749 | 4792 | | |
| |||
4925 | 4968 | | |
4926 | 4969 | | |
4927 | 4970 | | |
4928 | | - | |
| 4971 | + | |
4929 | 4972 | | |
4930 | | - | |
4931 | | - | |
4932 | | - | |
| 4973 | + | |
| 4974 | + | |
| 4975 | + | |
4933 | 4976 | | |
4934 | | - | |
4935 | | - | |
4936 | | - | |
| 4977 | + | |
| 4978 | + | |
| 4979 | + | |
4937 | 4980 | | |
4938 | 4981 | | |
4939 | 4982 | | |
| |||
4946 | 4989 | | |
4947 | 4990 | | |
4948 | 4991 | | |
4949 | | - | |
4950 | | - | |
| 4992 | + | |
| 4993 | + | |
4951 | 4994 | | |
4952 | 4995 | | |
4953 | 4996 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
791 | 791 | | |
792 | 792 | | |
793 | 793 | | |
794 | | - | |
795 | | - | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
796 | 804 | | |
797 | 805 | | |
798 | 806 | | |
| |||
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| |||
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
488 | 489 | | |
489 | 490 | | |
490 | 491 | | |
| |||
0 commit comments