add error handling for on mount useEffect of AuthenticateUserModal
This commit is contained in:
parent
f611ff2a6a
commit
e0ffb6e9f3
|
@ -8,6 +8,7 @@ import VerifyMasterPasswordForm, {
|
|||
VerifyMasterPasswordFormProps,
|
||||
} from 'components/VerifyMasterPasswordForm';
|
||||
import { Dialog, Stack, Typography } from '@mui/material';
|
||||
import { logError } from 'utils/sentry';
|
||||
|
||||
interface Iprops {
|
||||
open: boolean;
|
||||
|
@ -33,20 +34,28 @@ export default function AuthenticateUserModal({
|
|||
|
||||
useEffect(() => {
|
||||
const main = async () => {
|
||||
try {
|
||||
const user = getData(LS_KEYS.USER);
|
||||
if (!user) {
|
||||
throw Error('User not found');
|
||||
}
|
||||
setUser(user);
|
||||
const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);
|
||||
|
||||
if (
|
||||
(!user?.token && !user?.encryptedToken) ||
|
||||
(keyAttributes && !keyAttributes.memLimit)
|
||||
) {
|
||||
somethingWentWrong();
|
||||
throw Error('User not logged in');
|
||||
} else if (!keyAttributes) {
|
||||
somethingWentWrong();
|
||||
throw Error('Key attributes not found');
|
||||
} else {
|
||||
setKeyAttributes(keyAttributes);
|
||||
}
|
||||
} catch (e) {
|
||||
logError(e, 'AuthenticateUserModal initialization failed');
|
||||
onClose();
|
||||
somethingWentWrong();
|
||||
}
|
||||
};
|
||||
main();
|
||||
}, []);
|
||||
|
|
Loading…
Reference in a new issue