From c583b26355e6c50448c090eead35c9e05b0fbd20 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Fri, 21 Aug 2026 23:18:23 +0200 Subject: [PATCH] refactor(user): apply change on update entries --- frontend/src/lib/api/endpoints/profile.ts | 6 +++--- frontend/src/routes/profile/+page.svelte | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/src/lib/api/endpoints/profile.ts b/frontend/src/lib/api/endpoints/profile.ts index 9b1e003d..6305b215 100644 --- a/frontend/src/lib/api/endpoints/profile.ts +++ b/frontend/src/lib/api/endpoints/profile.ts @@ -1,7 +1,7 @@ /** Profile / account endpoints — ported from views/profile/profile.js. */ import { apiFetch } from '$lib/api/client'; import { getCsrfHeaders } from '$lib/api/csrf'; -import type { PublicUser } from '$lib/api/types'; +import type { SelfUser } from '$lib/api/types'; import { t } from '$lib/i18n/index.svelte'; const JSON_HEADERS = { 'Content-Type': 'application/json' }; @@ -24,7 +24,7 @@ export interface ProfilePatch { ui_preferences?: Record; } -export async function updateProfile(patch: ProfilePatch): Promise { +export async function updateProfile(patch: ProfilePatch): Promise { const res = await apiFetch('/api/auth/me/profile', { method: 'PATCH', credentials: 'same-origin', @@ -57,7 +57,7 @@ export async function updateProfile(patch: ProfilePatch): Promise { } throw new Error(err.message || err.error || `profile update failed: ${res.status}`); } - return (await res.json()) as PublicUser; + return (await res.json()) as SelfUser; } export async function changePassword(currentPw: string, newPw: string): Promise { diff --git a/frontend/src/routes/profile/+page.svelte b/frontend/src/routes/profile/+page.svelte index d0b7539b..217e091e 100644 --- a/frontend/src/routes/profile/+page.svelte +++ b/frontend/src/routes/profile/+page.svelte @@ -210,13 +210,13 @@ savingProfile = true; try { - await updateProfile(patch); - // Server returns the truncated `PublicUser` shape; re-fetch - // `/me` so `session.me` picks up self-only edits (locale, - // notify_on_share, ui_preferences bag) as well as the public - // identity changes. `session.user` is a derived accessor over - // `session.me.full.user`, so it updates in lockstep. - await session.refresh(); + // PATCH /me/profile echoes SelfUser (same shape as GET /me) + // so the SPA absorbs the just-written state in one round + // trip — no follow-up refresh needed. `session.user` is a + // derived accessor over `session.me.full.user`, so it + // updates in lockstep with the me assignment. + const updated = await updateProfile(patch); + session.me = updated; if (patch.preferred_locale) await setLocale(patch.preferred_locale as Locale); ui.notify(t('profile.saved', 'Profile saved'), 'success'); } catch (err) {