logout if 404 as twoFactorSession has expired
This commit is contained in:
parent
b429cd4985
commit
867356b131
|
@ -1,9 +1,8 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import { Formik, FormikHelpers } from 'formik';
|
||||
import router from 'next/router';
|
||||
import { DeadCenter } from 'pages/gallery';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { Form, FormControl } from 'react-bootstrap';
|
||||
import { Form } from 'react-bootstrap';
|
||||
import OtpInput from 'react-otp-input';
|
||||
import constants from 'utils/strings/constants';
|
||||
import SubmitButton from './SubmitButton';
|
||||
|
@ -64,6 +63,7 @@ export default function VerifyTwoFactor(props: Props) {
|
|||
<DeadCenter>
|
||||
<OtpInput
|
||||
ref={otpInputRef}
|
||||
shouldAutoFocus
|
||||
value={values.otp}
|
||||
onChange={(otp) => {
|
||||
onChange(otp, handleChange('otp'), submitForm);
|
||||
|
|
|
@ -27,17 +27,25 @@ export default function Home() {
|
|||
}, []);
|
||||
|
||||
const onSubmit = async (otp: string) => {
|
||||
const resp = await verifyTwoFactor(otp, sessionID);
|
||||
const { keyAttributes, encryptedToken, token, id } = resp;
|
||||
setData(LS_KEYS.USER, {
|
||||
...getData(LS_KEYS.USER),
|
||||
email,
|
||||
token,
|
||||
encryptedToken,
|
||||
id,
|
||||
});
|
||||
setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);
|
||||
router.push('/credentials');
|
||||
try {
|
||||
const resp = await verifyTwoFactor(otp, sessionID);
|
||||
const { keyAttributes, encryptedToken, token, id } = resp;
|
||||
setData(LS_KEYS.USER, {
|
||||
...getData(LS_KEYS.USER),
|
||||
email,
|
||||
token,
|
||||
encryptedToken,
|
||||
id,
|
||||
});
|
||||
setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);
|
||||
router.push('/credentials');
|
||||
} catch (e) {
|
||||
if (e.status === 404) {
|
||||
logoutUser();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Container>
|
||||
|
|
Loading…
Reference in a new issue