From a0b10e688cd96ecbab767bed4ee1abdd5aefc4db Mon Sep 17 00:00:00 2001 From: Fringg Date: Wed, 11 Feb 2026 18:28:49 +0300 Subject: [PATCH] fix: allow email change for unverified emails without code verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Skip code-based flow for unverified emails — replace email directly and send verification to the new address. Show success step immediately instead of asking for a verification code. --- src/api/auth.ts | 4 +++- src/pages/Profile.tsx | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index 4cf23a5..798d587 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -110,7 +110,9 @@ export const authApi = { }, // Request email change - sends verification code to new email - requestEmailChange: async (newEmail: string): Promise<{ message: string }> => { + requestEmailChange: async ( + newEmail: string, + ): Promise<{ message: string; new_email: string; expires_in_minutes: number }> => { const response = await apiClient.post('/cabinet/auth/email/change', { new_email: newEmail, }); diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index 389c074..b811f23 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -181,10 +181,17 @@ export default function Profile() { // Email change mutations const requestEmailChangeMutation = useMutation({ mutationFn: (emailAddr: string) => authApi.requestEmailChange(emailAddr), - onSuccess: () => { + onSuccess: async (data) => { setChangeError(null); - setChangeEmailStep('code'); - setResendCooldown(UI.RESEND_COOLDOWN_SEC); + if (data.expires_in_minutes === 0) { + // Unverified email was replaced directly + setChangeEmailStep('success'); + const updatedUser = await authApi.getMe(); + setUser(updatedUser); + } else { + setChangeEmailStep('code'); + setResendCooldown(UI.RESEND_COOLDOWN_SEC); + } }, onError: (err: { response?: { data?: { detail?: string } } }) => { const detail = err.response?.data?.detail;