Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Cleanup

Manav Rathiaf89a2202cae
diff --git a/web/packages/accounts/components/Verify2FACodeForm.tsx b/web/packages/accounts/components/Verify2FACodeForm.tsx
index c11e3872d6..d83dba61cb 100644
--- a/web/packages/accounts/components/Verify2FACodeForm.tsx
+++ b/web/packages/accounts/components/Verify2FACodeForm.tsx
@@ -36,13 +36,21 @@ export const Verify2FACodeForm: React.FC<Verify2FACodeFormProps> = ({
}) => {
const [shouldAutoFocus, setShouldAutoFocus] = useState(true);
- const formik = useFormik<{ otp: string }>({
+ const {
+ values,
+ errors,
+ handleChange,
+ handleSubmit,
+ submitForm,
+ isSubmitting,
+ } = useFormik<{ otp: string }>({
initialValues: { otp: "" },
validateOnBlur: false,
validateOnChange: false,
onSubmit: async ({ otp }, { setFieldError, resetForm }) => {
try {
await onSubmit(otp);
+ resetForm(); // Prevent resubmission via the useEffect.
} catch (e) {
log.error("Failed to submit 2FA code", e);
resetForm();
@@ -61,23 +69,6 @@ export const Verify2FACodeForm: React.FC<Verify2FACodeFormProps> = ({
},
});
- const {
- values,
- errors,
- handleChange,
- handleSubmit,
- submitForm,
- isSubmitting,
- } = formik;
-
- // const onChange =
- // // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
- // (callback: Function, triggerSubmit: Function) => (otp: string) => {
- // callback(otp);
- // if (otp.length === 6) {
- // triggerSubmit(otp);
- // }
- // };
useEffect(() => {
if (values.otp.length == 6 && !isSubmitting) void submitForm();
}, [values, isSubmitting]);