move passphrase and confirm check before otp

This commit is contained in:
Abhinav 2022-12-21 16:47:25 +05:30
parent e05f21447d
commit ee81cbfd79

View file

@ -47,8 +47,12 @@ export default function SignUp(props: SignUpProps) {
{ email, passphrase, confirm }: FormValues, { email, passphrase, confirm }: FormValues,
{ setFieldError }: FormikHelpers<FormValues> { setFieldError }: FormikHelpers<FormValues>
) => { ) => {
setLoading(true);
try { try {
if (passphrase !== confirm) {
setFieldError('confirm', constants.PASSPHRASE_MATCH_ERROR);
return;
}
setLoading(true);
try { try {
setData(LS_KEYS.USER, { email }); setData(LS_KEYS.USER, { email });
await sendOtt(email); await sendOtt(email);
@ -60,30 +64,23 @@ export default function SignUp(props: SignUpProps) {
throw e; throw e;
} }
try { try {
if (passphrase === confirm) { const { keyAttributes, masterKey } =
const { keyAttributes, masterKey } = await generateKeyAttributes(passphrase);
await generateKeyAttributes(passphrase); setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes);
setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); await generateAndSaveIntermediateKeyAttributes(
await generateAndSaveIntermediateKeyAttributes( passphrase,
passphrase, keyAttributes,
keyAttributes, masterKey
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
); );
await saveKeyInSessionStore(
SESSION_KEYS.ENCRYPTION_KEY,
masterKey
);
setJustSignedUp(true);
router.push(PAGES.VERIFY);
} catch (e) {
setFieldError('confirm', constants.PASSWORD_GENERATION_FAILED);
throw e; throw e;
} }
} catch (err) { } catch (err) {