From ef531f79b26538afb3aa0e2b83431c2716b9991d Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 12 Apr 2026 23:31:24 +0200 Subject: [PATCH] fix: update email display in UI after email change The OIDC session token retains the old email after a Logto email change. Now the server returns the new email in the response and the frontend optimistically updates the auth cache. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/client/hooks/useAccount.ts | 10 +++++++--- src/server/routes/account.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/client/hooks/useAccount.ts b/src/client/hooks/useAccount.ts index f744d80..44f061d 100644 --- a/src/client/hooks/useAccount.ts +++ b/src/client/hooks/useAccount.ts @@ -20,9 +20,13 @@ export function useChangeEmail() { const queryClient = useQueryClient(); return useMutation({ mutationFn: (data: { newEmail: string }) => - apiPost<{ ok: boolean }>("/api/account/email", data), - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ["auth"] }); + apiPost<{ ok: boolean; email: string }>("/api/account/email", data), + onSuccess: (_data, variables) => { + // Update auth cache with new email since the OIDC session still has the old one + queryClient.setQueryData(["auth"], (old: any) => { + if (!old?.user) return old; + return { ...old, user: { ...old.user, email: variables.newEmail } }; + }); }, }); } diff --git a/src/server/routes/account.ts b/src/server/routes/account.ts index d9e171f..d9cd450 100644 --- a/src/server/routes/account.ts +++ b/src/server/routes/account.ts @@ -70,7 +70,7 @@ app.post("/email", zValidator("json", changeEmailSchema), async (c) => { const logtoSub = await getLogtoSub(db, userId); await logtoClient.updateEmail(logtoSub, newEmail); - return c.json({ ok: true }); + return c.json({ ok: true, email: newEmail }); }); // ── Has Password ────────────────────────────────────────────────────