diff --git a/ui/src/user/UserEdit.jsx b/ui/src/user/UserEdit.jsx index c5d9c75a4..f3cf01073 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 74405cc13..66c7eee40 100644 --- a/ui/src/user/UserEdit.test.jsx +++ b/ui/src/user/UserEdit.test.jsx @@ -147,6 +147,7 @@ describe('', () => { beforeEach(() => { vi.clearAllMocks() hooks.save = null + localStorage.clear() }) it('notifies success and redirects when the update succeeds', async () => { @@ -197,5 +198,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') + }) }) })