feat: implement mutual exclusion and warnings between Google Authenticator and Email 2FA
This commit is contained in:
@@ -151,8 +151,18 @@ export default function SettingsIndex({ twoFactor }: SettingsProps) {
|
||||
setTimeout(() => setCopiedSecret(false), 2000);
|
||||
};
|
||||
|
||||
const handleEnable2FA = (e: React.SyntheticEvent) => {
|
||||
const handleEnable2FA = async (e: React.SyntheticEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (twoFactor.email_enabled) {
|
||||
const warning = await swal.confirm(
|
||||
'Deactivate Email 2FA?',
|
||||
'Enabling Google Authenticator will automatically deactivate Email Two-Factor Authentication. Do you want to proceed?',
|
||||
'Proceed'
|
||||
);
|
||||
if (!warning.isConfirmed) return;
|
||||
}
|
||||
|
||||
twoFactorForm.post(route('two-factor.enable'), {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => { twoFactorForm.reset(); swal.success('Enabled', '2FA is now active on your account.'); },
|
||||
@@ -188,6 +198,15 @@ export default function SettingsIndex({ twoFactor }: SettingsProps) {
|
||||
};
|
||||
|
||||
const handleToggleEmail2FA = async (enable: boolean) => {
|
||||
if (enable && twoFactor.enabled) {
|
||||
const warning = await swal.confirm(
|
||||
'Switch to Email 2FA?',
|
||||
'Enabling Email 2FA will automatically deactivate your Google Authenticator setup. Do you want to proceed?',
|
||||
'Proceed'
|
||||
);
|
||||
if (!warning.isConfirmed) return;
|
||||
}
|
||||
|
||||
const { value: password } = await Swal.fire({
|
||||
title: enable ? 'Enable Email 2FA' : 'Disable Email 2FA',
|
||||
text: 'Enter your password to confirm.',
|
||||
|
||||
Reference in New Issue
Block a user