From 1b230f0d7afb278c77c4b036f8263a11bb4ed6ff Mon Sep 17 00:00:00 2001 From: Carlos Monastyrski Date: Tue, 16 Sep 2025 13:18:37 -0300 Subject: [PATCH] Enable email login on change of emails flows to avoid blocked users --- backend/src/services/user/user-service.ts | 9 ++++++++- .../platform/auth-methods/email-password.mdx | 3 +++ .../components/ChangeEmailSection/ChangeEmailSection.tsx | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts index f97e98fa3..b8058f327 100644 --- a/backend/src/services/user/user-service.ts +++ b/backend/src/services/user/user-service.ts @@ -294,11 +294,18 @@ export const userServiceFactory = ({ // Delete all user aliases since the email is changing await userAliasDAL.delete({ userId }, tx); + // Ensure EMAIL auth method is included if not already present + const currentAuthMethods = user.authMethods || []; + const updatedAuthMethods = currentAuthMethods.includes(AuthMethod.EMAIL) + ? currentAuthMethods + : [...currentAuthMethods, AuthMethod.EMAIL]; + const updatedUser = await userDAL.updateById( userId, { email: newEmail.toLowerCase(), - username: newEmail.toLowerCase() + username: newEmail.toLowerCase(), + authMethods: updatedAuthMethods }, tx ); diff --git a/docs/documentation/platform/auth-methods/email-password.mdx b/docs/documentation/platform/auth-methods/email-password.mdx index f5cb0e6f5..fa22d4d1d 100644 --- a/docs/documentation/platform/auth-methods/email-password.mdx +++ b/docs/documentation/platform/auth-methods/email-password.mdx @@ -29,6 +29,9 @@ You can update your account email address: 1. Open the `Personal Settings` menu. 2. Navigate to the `Authentication` tab. 3. In the `Change Email` section, enter your new email address. + +If you don't currently have Email authentication enabled, it will be automatically activated when you change your email. You can change this back in your authentication settings after logging in with your new email if desired. + ![change email section](../../../images/auth-methods/personal-settings-authentication-change-email-password.png) 4. Click `Send Verification Code` to receive an 6-digit verification code at your new email address. 5. Check your new email inbox and enter the verification code. diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/ChangeEmailSection/ChangeEmailSection.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/ChangeEmailSection/ChangeEmailSection.tsx index 723ed7498..78a2265cc 100644 --- a/frontend/src/pages/user/PersonalSettingsPage/components/ChangeEmailSection/ChangeEmailSection.tsx +++ b/frontend/src/pages/user/PersonalSettingsPage/components/ChangeEmailSection/ChangeEmailSection.tsx @@ -10,6 +10,7 @@ import { Button, FormControl, Input, Modal, ModalContent } from "@app/components import { useUser } from "@app/context"; import { useRequestEmailChangeOTP, useUpdateUserEmail } from "@app/hooks/api/users"; import { clearSession } from "@app/hooks/api/users/queries"; +import { AuthMethod } from "@app/hooks/api/users/types"; const emailSchema = z .object({ @@ -43,6 +44,7 @@ const otpInputProps = { export const ChangeEmailSection = () => { const navigate = useNavigate(); const { user } = useUser(); + const hasEmailAuth = user?.authMethods?.includes(AuthMethod.EMAIL) ?? false; const [isOTPModalOpen, setIsOTPModalOpen] = useState(false); const [pendingEmail, setPendingEmail] = useState(""); @@ -177,6 +179,11 @@ export const ChangeEmailSection = () => { label="New email address" isError={Boolean(error)} errorText={error?.message} + tooltipText={ + hasEmailAuth + ? "Your email authentication method is currently enabled and will remain active after changing your email." + : "Email authentication method will be automatically enabled after changing your email. You can change this back after logging in with your new email if desired." + } >