Repository navigation
Commit 58e1a3b
fix(auth, console): saving your profile keeps the page on screen and shows its confirmation (#36984)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBDHJBvzScLgkhKgms97sNuU)_
repo:objectstack#3 · os-support-ai · session_01WGufzhoBbwh8URjwQHde8v
Fixes #36972
Clause-②: no
Metadata-protocol: none
Tests (final head `3147c224723`): `@object-ui/auth` full suite (50 files
/ 523 tests) + `type-check`; `ProfilePage*` suites of
`@object-ui/console` (5 files / 47 tests) + `type-check`; derived gate
families listed under Verification. Full `Test UI` is CI's.
## 维护者速读
-
用户在个人资料页保存姓名(或更换头像)后,页面不再闪白重载,「个人资料已更新」的提示会留在卡片上;在语言卡片保存后,即使界面语言随之切换,也会弹出「语言偏好已更新」的提示。
- 修的是账户应用的个人资料页,替使用控制台的每一位用户解决「点了保存却毫无反馈」的问题。
- 若出错,最坏情况是保存后页面右上角的姓名或头像要等下次刷新会话才与服务器完全一致;改动只在两个前端包内,可以直接撤回。
- 无。
## What changes
- **Root cause (name card).** `useAuth().updateUser` installed the
answer of better-auth's `POST /update-user` as the session user.
better-auth 1.7.12 answers that endpoint with `{ status: true }` (its
route source returns exactly that, read in this tree's `node_modules`),
not the user. For a moment the session user had no `id`, `name` or
`email`: the header showed "?" / "User", the console's
`/auth/me/permissions` request key (`user.id` + org) went from defined
to `undefined`, and `MePermissionsProvider` swapped its children for the
loading fallback and mounted them again. That is the blank `main`, the
refetch burst the card lists, and the lost `saved` state. `updateUser`
now keeps the same user and spreads the written fields over it
(`ui/packages/auth/src/AuthProvider.tsx`), which is how better-auth
builds the stored row server-side. The identity never changes, so
nothing keyed on it remounts. This is candidate (c) from the dispatch:
stop the needless remount at its source. **The page no longer blanks**
on a name save, and the inline "Profile updated successfully." alert
stays. The avatar upload and remove paths call `updateUser` too and get
the same fix.
- **Language card.** A save that changes the interface language remounts
the page by design: the signed-in user's locale reader applies the new
`sys_user.locale` and the console shell remounts its metadata subtree
under `key={language}`. That shell behaviour is left as it is, since it
is how server-resolved labels relabel. The card now also confirms with
`toast.success` (sonner, the console's toast, with the existing
`profile.language.saved` key and a stable toast id), and the console
toaster is mounted above that key. **The page still remounts on a
language change** (by design), and the confirmation survives it. A save
that does not change the UI language shows the inline alert as before,
plus the toast.
- One changeset: `@object-ui/auth` and `@object-ui/console`, both
published (neither is `private`), both `patch`.
## Tests
- `AuthProvider.test.tsx`, new describe "updateUser keeps the signed-in
identity": the client double answers `{ status: true }`, the real
server's shape. A child keyed on `user?.id` (as the console keys its
permissions answer) must not remount, the clicked button must stay in
the document, `id`/`email` kept, `name` updated.
- `ProfilePage.language.test.tsx`, new describe "the language save
confirms after a language remount": a real sonner `Toaster` outside a
subtree keyed on the language. (1) A write whose settling switches the
key: the old select leaves the document, a new card mounts, and
"Language preference updated." is on screen inside
`[data-sonner-toaster]`. (2) Control: a save with no language change.
The same select stays, and the inline `role=alert` carries the sentence.
## Acceptance notes
- Reproduction on main: the dispatch asked for a code-path repro. The
chain above was read on `144d368eac1`. The ablation leg of the
AuthProvider pin restores main's semantics (installs the client's answer
as the user) and fails with `expected 'undefined' to be 'Grace'`, so the
remount mechanism (identity lost) is live on main.
- `createAuthClient().updateUser` still declares `Promise<AuthUser>`
while the server answers `{ status: true }`. Its only consumer, the
provider, no longer reads that value, so this PR does not change the
exported `AuthClient` type. Changing it is a published-type change.
Noted here, not filed: after this PR it has no consumer.
- The existing `createAuthClient.test.ts` case "updateUser sends POST to
/update-user and returns user" mocks a `{ user }` body the server never
sends. Left untouched (outside this card's file surface).
- Sibling #36971 edits the same `ProfilePage.tsx` (the Language card's
description and the component comment). This PR does not touch those
lines. `git merge-tree` against
`origin/claude/issue-36971-profile-language-one-setting` is clean. The
new test describe sits mid-file so both branches' appended describes do
not collide.
## Verification
Two-minute check: open Account → Profile, change the name, click **Save
changes**. The header keeps the avatar and name, the page does not
flash, and "Profile updated successfully." stays under the card title.
Then pick a different interface language in the Language card and click
**Save**. The page relabels, and a "Language preference updated." toast
shows at the top right.
Files to read first, by risk: `ui/packages/auth/src/AuthProvider.tsx`
(the `updateUser` callback),
`ui/apps/console/src/pages/system/ProfilePage.tsx` (the `toast.success`
in `LanguageCard`'s `handleSave`).
<details><summary>Ablations (fix committed first; restore proven by blob
== HEAD and empty git diff HEAD)</summary>
- AuthProvider: `setUser((prev) => (prev ? { ...prev, ...data } :
prev));` replaced with installing the client's answer. Pin red:
`AssertionError: expected 'undefined' to be 'Grace'`, 1 failed.
Restored: blob `8ea37fc238ba` == HEAD.
- ProfilePage: the `toast.success(...)` call neutralised. Remount pin
red: `Unable to find an element with the text: Language preference
updated.`. The control stayed green (1 failed / 1 passed). Restored:
blob `282c6749015e` == HEAD.
</details>
<details><summary>Local gates</summary>
On head `3147c224723`, exit codes captured before any pipe:
- `node scripts/pm/dispatch-gates.mjs --commands` derived 38 families.
All 38 ran locally: 37 exited 0 on the first pass. `pnpm
check:query-options-erasure` hit my 300 s wrapper timeout (124) and
exited 0 on a 580 s re-run ("ratchet holds: … none new"). `pnpm --dir ui
exec vitest run scripts/` passed under the verify lock: 172 files
passed, 2 skipped; 5129 tests passed.
- `--ran` reconciliation: "38 derived famil(ies) accounted for — 38 run,
0 NOT-MEASURED".
- `node scripts/pm/overlap-check.mjs`: `VERDICT clean exit 0`. `git
merge-tree` against the #36971 branch: clean.
- CI families (Lint, Type Check UI, Test UI, Build & E2E UI and the
rest) are read from this PR's check-runs, not re-run locally.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzhoBbwh8URjwQHde8v -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 84b1e0c commit 58e1a3b
5 files changed
Lines changed: 194 additions & 4 deletions
File tree
- .changeset
- ui
- apps/console/src/pages/system
- __tests__
- packages/auth/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
686 | 687 | | |
687 | 688 | | |
688 | 689 | | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
689 | 699 | | |
690 | 700 | | |
691 | 701 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
275 | 277 | | |
276 | 278 | | |
277 | 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 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
278 | 360 | | |
279 | 361 | | |
280 | 362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
549 | | - | |
550 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
551 | 562 | | |
552 | 563 | | |
553 | 564 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
0 commit comments