Skip to content

Commit 701df27

Browse files
1 parent 625c6be commit 701df27

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/modules/Auth/utils/mfa.utils.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ describe('MFA Utilities', () => {
198198
it('preserves existing hyphen position', () => {
199199
expect(formatRecoveryCode('ABCDE-12345')).toBe('ABCDE-12345');
200200
});
201+
202+
it('handles deletion from formatted code without double hyphens', () => {
203+
// Simulate deleting from "ABCDE-12345" to "ABCD-12345"
204+
expect(formatRecoveryCode('ABCD-12345')).toBe('ABCD1-2345');
205+
// Simulate deleting all from second half: "ABCDE-" becomes "ABCDE"
206+
expect(formatRecoveryCode('ABCDE-')).toBe('ABCDE');
207+
// Simulate deleting from first half leaving hyphen: "ABC-12345"
208+
expect(formatRecoveryCode('ABC-12345')).toBe('ABC12-345');
209+
});
201210
});
202211

203212
describe('isValidMFACode', () => {

src/modules/Dashboard/features/AccountSettings/RemoveMFA/RemoveMFAConfirmation.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const StyledButton = styled('button')`
102102
padding: 10px 24px;
103103
display: flex;
104104
align-items: center;
105-
justify-center;
105+
justify-content: center;
106106
107107
&.primary {
108108
background: ${variables.palette.error};

src/modules/Dashboard/features/AccountSettings/shared/ConfirmIdentityRecoveryCode.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useTranslation } from 'react-i18next';
22
import { Box } from '@mui/material';
33

44
import { Svg } from 'shared/components/Svg';
5+
import { formatRecoveryCode } from 'modules/Auth/utils/mfa.utils';
56

67
import {
78
StyledDialog,
@@ -57,19 +58,9 @@ export const ConfirmIdentityRecoveryCode = ({
5758
const shouldDisableInput = !!onRetry;
5859

5960
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
60-
const value = e.target.value.toUpperCase();
61-
// Allow only alphanumeric characters and dash
62-
const sanitized = value.replace(/[^A-Z0-9-]/g, '');
63-
64-
// Auto-insert hyphen after 5 characters (format: XXXXX-XXXXX)
65-
if (sanitized.length === 5 && !sanitized.includes('-')) {
66-
setRecoveryCode(`${sanitized}-`);
67-
} else if (sanitized.length === 6 && sanitized.charAt(5) !== '-') {
68-
// If user pastes or types through, ensure hyphen is at position 5
69-
setRecoveryCode(`${sanitized.slice(0, 5)}-${sanitized.slice(5)}`);
70-
} else {
71-
setRecoveryCode(sanitized);
72-
}
61+
// Use the same formatting utility as login flow to avoid double-hyphen issues
62+
const formatted = formatRecoveryCode(e.target.value);
63+
setRecoveryCode(formatted);
7364
};
7465

7566
return (

0 commit comments

Comments
 (0)