fix: update email display in UI after email change
All checks were successful
CI / ci (push) Successful in 1m11s
CI / e2e (push) Has been skipped
CI / deploy (push) Successful in 14s

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) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 23:31:24 +02:00
parent 6108db3dab
commit ef531f79b2
2 changed files with 8 additions and 4 deletions

View File

@@ -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 } };
});
},
});
}

View File

@@ -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 ────────────────────────────────────────────────────