diff --git a/src/pages/two-factor/setup/index.tsx b/src/pages/two-factor/setup/index.tsx index 188caa973..c6986b118 100644 --- a/src/pages/two-factor/setup/index.tsx +++ b/src/pages/two-factor/setup/index.tsx @@ -3,7 +3,9 @@ import { enableTwoFactor, setupTwoFactor } from 'services/userService'; import constants from 'utils/strings/constants'; import VerticallyCentered from 'components/Container'; import { useRouter } from 'next/router'; -import VerifyTwoFactor from 'components/TwoFactor/VerifyForm'; +import VerifyTwoFactor, { + VerifyTwoFactorCallback, +} from 'components/TwoFactor/VerifyForm'; import { encryptWithRecoveryKey } from 'utils/crypto'; import { setData, LS_KEYS, getData } from 'utils/storage/localStorage'; import { AppContext, FLASH_MESSAGE_TYPE } from 'pages/_app'; @@ -13,6 +15,7 @@ import Card from '@mui/material/Card'; import { Box, CardContent, Typography } from '@mui/material'; import { TwoFactorSetup } from 'components/TwoFactor/Setup'; import LinkButton from 'components/pages/gallery/LinkButton'; +import { logError } from 'utils/sentry'; export enum SetupMode { QR_CODE, @@ -34,21 +37,21 @@ export default function SetupTwoFactor() { const twoFactorSecret = await setupTwoFactor(); setTwoFactorSecret(twoFactorSecret); } catch (e) { - appContext.setDisappearingFlashMessage({ - message: constants.TWO_FACTOR_SETUP_FAILED, - type: FLASH_MESSAGE_TYPE.DANGER, - }); - router.push(PAGES.GALLERY); + logError(e, 'failed to get two factor setup code'); } }; main(); }, []); - const onSubmit = async (otp: string) => { + const onSubmit: VerifyTwoFactorCallback = async ( + otp: string, + markSuccessful + ) => { const recoveryEncryptedTwoFactorSecret = await encryptWithRecoveryKey( twoFactorSecret.secretCode ); await enableTwoFactor(otp, recoveryEncryptedTwoFactorSecret); + await markSuccessful(); setData(LS_KEYS.USER, { ...getData(LS_KEYS.USER), isTwoFactorEnabled: true, diff --git a/src/pages/two-factor/verify/index.tsx b/src/pages/two-factor/verify/index.tsx index d2d284206..de393d3bf 100644 --- a/src/pages/two-factor/verify/index.tsx +++ b/src/pages/two-factor/verify/index.tsx @@ -1,4 +1,6 @@ -import VerifyTwoFactor from 'components/TwoFactor/VerifyForm'; +import VerifyTwoFactor, { + VerifyTwoFactorCallback, +} from 'components/TwoFactor/VerifyForm'; import router from 'next/router'; import React, { useEffect, useState } from 'react'; import { logoutUser, verifyTwoFactor } from 'services/userService'; @@ -33,7 +35,7 @@ export default function Home() { main(); }, []); - const onSubmit = async (otp: string) => { + const onSubmit: VerifyTwoFactorCallback = async (otp) => { try { const resp = await verifyTwoFactor(otp, sessionID); const { keyAttributes, encryptedToken, token, id } = resp;