From ee81cbfd7923f1a06ed3a965526c7f3b90b28123 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 21 Dec 2022 16:47:25 +0530 Subject: [PATCH] move passphrase and confirm check before otp --- src/components/SignUp.tsx | 45 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/components/SignUp.tsx b/src/components/SignUp.tsx index 8e8c25d68..e4c68985b 100644 --- a/src/components/SignUp.tsx +++ b/src/components/SignUp.tsx @@ -47,8 +47,12 @@ export default function SignUp(props: SignUpProps) { { email, passphrase, confirm }: FormValues, { setFieldError }: FormikHelpers ) => { - setLoading(true); try { + if (passphrase !== confirm) { + setFieldError('confirm', constants.PASSPHRASE_MATCH_ERROR); + return; + } + setLoading(true); try { setData(LS_KEYS.USER, { email }); await sendOtt(email); @@ -60,30 +64,23 @@ export default function SignUp(props: SignUpProps) { throw e; } try { - if (passphrase === confirm) { - const { keyAttributes, masterKey } = - await generateKeyAttributes(passphrase); - setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); - await generateAndSaveIntermediateKeyAttributes( - passphrase, - keyAttributes, - masterKey - ); - - await saveKeyInSessionStore( - SESSION_KEYS.ENCRYPTION_KEY, - masterKey - ); - setJustSignedUp(true); - router.push(PAGES.VERIFY); - } else { - setFieldError('confirm', constants.PASSPHRASE_MATCH_ERROR); - } - } catch (e) { - setFieldError( - 'passphrase', - constants.PASSWORD_GENERATION_FAILED + const { keyAttributes, masterKey } = + await generateKeyAttributes(passphrase); + setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); + await generateAndSaveIntermediateKeyAttributes( + passphrase, + keyAttributes, + masterKey ); + + await saveKeyInSessionStore( + SESSION_KEYS.ENCRYPTION_KEY, + masterKey + ); + setJustSignedUp(true); + router.push(PAGES.VERIFY); + } catch (e) { + setFieldError('confirm', constants.PASSWORD_GENERATION_FAILED); throw e; } } catch (err) {