Skip to content

Commit 540eadd

Browse files
authored
refactor(account): remove auto backup code generation after MFA binding (#8138)
Remove the automatic backup code generation check and navigation after binding passkey or TOTP. Users can still manually set up backup codes through the account center if needed.
1 parent e801822 commit 540eadd

File tree

2 files changed

+2
-43
lines changed

2 files changed

+2
-43
lines changed

packages/account/src/pages/PasskeyBinding/index.tsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,30 @@ import {
1212
createWebAuthnRegistration,
1313
verifyWebAuthnRegistration,
1414
addWebAuthnMfa,
15-
getMfaVerifications,
1615
} from '@ac/apis/mfa';
1716
import ErrorPage from '@ac/components/ErrorPage';
1817
import VerificationMethodList from '@ac/components/VerificationMethodList';
19-
import { backupCodesGenerateRoute, passkeySuccessRoute } from '@ac/constants/routes';
18+
import { passkeySuccessRoute } from '@ac/constants/routes';
2019
import useApi from '@ac/hooks/use-api';
2120
import useErrorHandler from '@ac/hooks/use-error-handler';
2221
import SecondaryPageLayout from '@ac/layouts/SecondaryPageLayout';
2322

2423
import styles from './index.module.scss';
2524

2625
const isWebAuthnEnabled = (mfa?: Mfa) => mfa?.factors.includes(MfaFactor.WebAuthn) ?? false;
27-
const isBackupCodeEnabled = (mfa?: Mfa) => mfa?.factors.includes(MfaFactor.BackupCode) ?? false;
2826

2927
const PasskeyBinding = () => {
3028
const { t } = useTranslation();
3129
const navigate = useNavigate();
3230
const { loading } = useContext(LoadingContext);
3331
const { accountCenterSettings, experienceSettings, verificationId, setVerificationId, setToast } =
3432
useContext(PageContext);
35-
const getMfaRequest = useApi(getMfaVerifications);
3633
const createRegistrationRequest = useApi(createWebAuthnRegistration);
3734
const verifyRegistrationRequest = useApi(verifyWebAuthnRegistration);
3835
const addWebAuthnRequest = useApi(addWebAuthnMfa);
3936
const handleError = useErrorHandler();
4037

4138
const [isWebAuthnSupported, setIsWebAuthnSupported] = useState<boolean>();
42-
const [hasBackupCodes, setHasBackupCodes] = useState<boolean>();
4339
// Pre-fetched WebAuthn registration options to ensure startRegistration() is called
4440
// synchronously in the click handler (required for iOS Safari/WKWebView user gesture)
4541
const [registrationData, setRegistrationData] = useState<{
@@ -75,23 +71,6 @@ const PasskeyBinding = () => {
7571
void fetchRegistrationOptions();
7672
}, [verificationId, createRegistrationRequest]);
7773

78-
// Check if user has backup codes
79-
useEffect(() => {
80-
const checkExistingMfa = async () => {
81-
const [error, result] = await getMfaRequest();
82-
83-
if (error) {
84-
setHasBackupCodes(false);
85-
return;
86-
}
87-
88-
const hasBackup = result?.some((mfa) => mfa.type === MfaFactor.BackupCode) ?? false;
89-
setHasBackupCodes(hasBackup);
90-
};
91-
92-
void checkExistingMfa();
93-
}, [getMfaRequest]);
94-
9574
const handleAddPasskey = useCallback(async () => {
9675
if (!verificationId || loading || !registrationData) {
9776
return;
@@ -143,18 +122,10 @@ const PasskeyBinding = () => {
143122
return;
144123
}
145124

146-
// Step 4: Navigate to success or backup code setup
147-
if (isBackupCodeEnabled(experienceSettings?.mfa) && !hasBackupCodes) {
148-
void navigate(backupCodesGenerateRoute, { replace: true });
149-
return;
150-
}
151-
152125
void navigate(passkeySuccessRoute, { replace: true });
153126
}, [
154127
addWebAuthnRequest,
155-
experienceSettings?.mfa,
156128
handleError,
157-
hasBackupCodes,
158129
loading,
159130
navigate,
160131
registrationData,

packages/account/src/pages/TotpBinding/index.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import PageContext from '@ac/Providers/PageContextProvider/PageContext';
1515
import { getMfaVerifications, generateTotpSecret, addTotpMfa } from '@ac/apis/mfa';
1616
import ErrorPage from '@ac/components/ErrorPage';
1717
import VerificationMethodList from '@ac/components/VerificationMethodList';
18-
import { authenticatorAppSuccessRoute, backupCodesGenerateRoute } from '@ac/constants/routes';
18+
import { authenticatorAppSuccessRoute } from '@ac/constants/routes';
1919
import useApi from '@ac/hooks/use-api';
2020
import useErrorHandler from '@ac/hooks/use-error-handler';
2121
import SecondaryPageLayout from '@ac/layouts/SecondaryPageLayout';
@@ -27,7 +27,6 @@ const isCodeReady = (code: string[]) => {
2727
};
2828

2929
const isTotpEnabled = (mfa?: Mfa) => mfa?.factors.includes(MfaFactor.TOTP) ?? false;
30-
const isBackupCodeEnabled = (mfa?: Mfa) => mfa?.factors.includes(MfaFactor.BackupCode) ?? false;
3130

3231
const TotpBinding = () => {
3332
const { t } = useTranslation();
@@ -52,7 +51,6 @@ const TotpBinding = () => {
5251
const [codeInput, setCodeInput] = useState<string[]>([]);
5352
const [errorMessage, setErrorMessage] = useState<string>();
5453
const [hasTotpAlready, setHasTotpAlready] = useState<boolean>();
55-
const [hasBackupCodes, setHasBackupCodes] = useState<boolean>();
5654

5755
// Check if TOTP already exists on mount
5856
useEffect(() => {
@@ -62,14 +60,11 @@ const TotpBinding = () => {
6260
if (error) {
6361
// If there's an error, we'll let the user continue and the backend will validate
6462
setHasTotpAlready(false);
65-
setHasBackupCodes(false);
6663
return;
6764
}
6865

6966
const hasTotp = result?.some((mfa) => mfa.type === MfaFactor.TOTP) ?? false;
70-
const hasBackup = result?.some((mfa) => mfa.type === MfaFactor.BackupCode) ?? false;
7167
setHasTotpAlready(hasTotp);
72-
setHasBackupCodes(hasBackup);
7368
};
7469

7570
void checkExistingMfa();
@@ -144,19 +139,12 @@ const TotpBinding = () => {
144139
return;
145140
}
146141

147-
if (isBackupCodeEnabled(experienceSettings?.mfa) && !hasBackupCodes) {
148-
void navigate(backupCodesGenerateRoute, { replace: true });
149-
return;
150-
}
151-
152142
void navigate(authenticatorAppSuccessRoute, { replace: true });
153143
},
154144
[
155145
addTotpRequest,
156146
codeInput,
157-
experienceSettings?.mfa,
158147
handleError,
159-
hasBackupCodes,
160148
loading,
161149
navigate,
162150
secret,

0 commit comments

Comments
 (0)