From 7df4900e5be66fe17678082da2d3d49bfb1dc093 Mon Sep 17 00:00:00 2001 From: junkerderprovinz Date: Sun, 9 Aug 2026 16:34:43 +0200 Subject: [PATCH] fix(ui): sync stored identity name when editing your own profile (#5388) Signed-off-by: junkerderprovinz --- ui/src/user/UserEdit.jsx | 8 +++++++- ui/src/user/UserEdit.test.jsx | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ui/src/user/UserEdit.jsx b/ui/src/user/UserEdit.jsx index d8302a9f9..c6087f13e 100644 --- a/ui/src/user/UserEdit.jsx +++ b/ui/src/user/UserEdit.jsx @@ -94,6 +94,12 @@ const UserEdit = (props) => { notify('resources.user.notifications.updated', 'info', { smart_count: 1, }) + // Keep the locally stored identity name in sync when users edit their + // own profile, so the app bar menu (and the ExtAuth logout/login reload, + // which reads localStorage.name via getIdentity) reflect the new name. + if (isMyself) { + localStorage.setItem('name', values.name) + } permissions === 'admin' ? redirect('/user') : refresh() } catch (error) { if (error?.body?.errors) { @@ -102,7 +108,7 @@ const UserEdit = (props) => { notify('ra.page.error', 'warning') } }, - [mutate, notify, permissions, redirect, refresh], + [isMyself, mutate, notify, permissions, redirect, refresh], ) // Custom validation function diff --git a/ui/src/user/UserEdit.test.jsx b/ui/src/user/UserEdit.test.jsx index 1d8290569..bc05f5acd 100644 --- a/ui/src/user/UserEdit.test.jsx +++ b/ui/src/user/UserEdit.test.jsx @@ -141,6 +141,7 @@ describe('', () => { beforeEach(() => { vi.clearAllMocks() hooks.save = null + localStorage.clear() }) it('notifies success and redirects when the update succeeds', async () => { @@ -191,5 +192,26 @@ describe('', () => { expect(hooks.notify).toHaveBeenCalledWith('ra.page.error', 'warning') expect(hooks.redirect).not.toHaveBeenCalled() }) + + it('syncs the stored identity name when editing your own profile', async () => { + localStorage.setItem('userId', 'user1') + hooks.mutate.mockResolvedValue({ data: defaultUser }) + render() + + await hooks.save({ id: 'user1', name: 'Renamed' }) + + expect(localStorage.getItem('name')).toBe('Renamed') + }) + + it('does not touch the stored identity name when editing another user', async () => { + localStorage.setItem('userId', 'admin1') + localStorage.setItem('name', 'Admin User') + hooks.mutate.mockResolvedValue({ data: defaultUser }) + render() + + await hooks.save({ id: 'user1', name: 'Renamed' }) + + expect(localStorage.getItem('name')).toBe('Admin User') + }) }) })