mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
fix: allow email change for unverified emails without code verification
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.
This commit is contained in:
@@ -110,7 +110,9 @@ export const authApi = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Request email change - sends verification code to new email
|
// 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', {
|
const response = await apiClient.post('/cabinet/auth/email/change', {
|
||||||
new_email: newEmail,
|
new_email: newEmail,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -181,10 +181,17 @@ export default function Profile() {
|
|||||||
// Email change mutations
|
// Email change mutations
|
||||||
const requestEmailChangeMutation = useMutation({
|
const requestEmailChangeMutation = useMutation({
|
||||||
mutationFn: (emailAddr: string) => authApi.requestEmailChange(emailAddr),
|
mutationFn: (emailAddr: string) => authApi.requestEmailChange(emailAddr),
|
||||||
onSuccess: () => {
|
onSuccess: async (data) => {
|
||||||
setChangeError(null);
|
setChangeError(null);
|
||||||
setChangeEmailStep('code');
|
if (data.expires_in_minutes === 0) {
|
||||||
setResendCooldown(UI.RESEND_COOLDOWN_SEC);
|
// 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 } } }) => {
|
onError: (err: { response?: { data?: { detail?: string } } }) => {
|
||||||
const detail = err.response?.data?.detail;
|
const detail = err.response?.data?.detail;
|
||||||
|
|||||||
Reference in New Issue
Block a user