Not awaiting promises to retain existing behavior

This commit is contained in:
Manav Rathi
2024-11-20 09:28:55 +05:30
parent 1ddd143b2e
commit af82ef194d
18 changed files with 55 additions and 53 deletions

View File

@@ -166,6 +166,7 @@ export const verifySRPSession = async (
log.error("verifySRPSession failed", e);
if (
e instanceof ApiError &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
e.httpStatusCode === HttpStatusCode.Unauthorized
) {
throw Error(CustomError.INCORRECT_PASSWORD);

View File

@@ -61,6 +61,7 @@ export const logout = async () => {
// ignore if unauthorized, can be triggered during on token expiry.
else if (
e instanceof ApiError &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
e.httpStatusCode === HttpStatusCode.Unauthorized
) {
return;

View File

@@ -31,10 +31,10 @@ export const Login: React.FC<LoginProps> = ({ signUp, host }) => {
log.debug(() => ["srpAttributes", JSON.stringify(srpAttributes)]);
if (!srpAttributes || srpAttributes.isEmailMFAEnabled) {
await sendOtt(email);
router.push(PAGES.VERIFY);
void router.push(PAGES.VERIFY);
} else {
setData(LS_KEYS.SRP_ATTRIBUTES, srpAttributes);
router.push(PAGES.CREDENTIALS);
void router.push(PAGES.CREDENTIALS);
}
} catch (e) {
if (e instanceof Error) {

View File

@@ -101,7 +101,7 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
const response =
await checkPasskeyVerificationStatus(passkeySessionID);
if (!response) setVerificationStatus("pending");
else router.push(await saveCredentialsAndNavigateTo(response));
else void router.push(await saveCredentialsAndNavigateTo(response));
} catch (e) {
log.error("Passkey verification status check failed", e);
showMiniDialog(
@@ -115,7 +115,7 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
};
const handleRecover = () => {
router.push("/passkeys/recover");
void router.push("/passkeys/recover");
};
return (

View File

@@ -109,7 +109,7 @@ export const SignUp: React.FC<SignUpProps> = ({ router, login, host }) => {
masterKey,
);
setJustSignedUp(true);
router.push(PAGES.VERIFY);
void router.push(PAGES.VERIFY);
} catch (e) {
setFieldError("confirm", t("PASSWORD_GENERATION_FAILED"));
throw e;

View File

@@ -17,8 +17,6 @@ export default [
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-call": "off",
/** TODO: Disabled as we migrate, try to prune these again */
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/array-type": "off",
"@typescript-eslint/no-empty-function": "off",

View File

@@ -24,7 +24,7 @@ const Page: React.FC<PageProps> = () => {
useEffect(() => {
const user = getData(LS_KEYS.USER);
if (!user?.token) {
router.push("/");
void router.push("/");
}
}, []);
@@ -83,7 +83,7 @@ const ChangeEmailForm: React.FC = () => {
await changeEmail(email, ott!);
await setLSUser({ ...getData(LS_KEYS.USER), email });
setLoading(false);
goToApp();
void goToApp();
} catch (e) {
setLoading(false);
setFieldError("ott", t("INCORRECT_CODE"));

View File

@@ -47,7 +47,7 @@ const Page: React.FC<PageProps> = () => {
setUser(user);
if (!user?.token) {
stashRedirect(PAGES.CHANGE_PASSWORD);
router.push("/");
void router.push("/");
} else {
setToken(user.token);
}
@@ -132,7 +132,7 @@ const Page: React.FC<PageProps> = () => {
const redirectToAppHome = () => {
setData(LS_KEYS.SHOW_BACK_BUTTON, { value: true });
router.push(appHomeRoute);
void router.push(appHomeRoute);
};
// TODO: Handle the case where user is not loaded yet.

View File

@@ -119,7 +119,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const main = async () => {
const user: User = getData(LS_KEYS.USER);
if (!user?.email) {
router.push("/");
void router.push("/");
return;
}
setUser(user);
@@ -141,7 +141,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
}
const token = getToken();
if (key && token) {
router.push(appHomeRoute);
void router.push(appHomeRoute);
return;
}
const kekEncryptedAttributes: B64EncryptionResult = getKey(
@@ -180,7 +180,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
(keyAttributes && !keyAttributes.memLimit)
) {
clearLocalStorage();
router.push("/");
void router.push("/");
return;
}
setKeyAttributes(keyAttributes);
@@ -190,10 +190,10 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
if (srpAttributes) {
setSrpAttributes(srpAttributes);
} else {
router.push("/");
void router.push("/");
}
};
main();
void main();
showNavBar(true);
}, []);
// TODO: ^ validateSession is a dependency, but add that only after we've
@@ -252,7 +252,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
twoFactorSessionID,
isTwoFactorEnabled: true,
});
router.push(PAGES.TWO_FACTOR_VERIFY);
void router.push(PAGES.TWO_FACTOR_VERIFY);
throw Error(CustomError.TWO_FACTOR_ENABLED);
} else {
const user = getData(LS_KEYS.USER);
@@ -314,7 +314,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
} catch (e) {
log.error("migrate to srp failed", e);
}
router.push(unstashRedirect() ?? appHomeRoute);
void router.push(unstashRedirect() ?? appHomeRoute);
} catch (e) {
log.error("useMasterPassword failed", e);
}

View File

@@ -51,22 +51,22 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const user: User = getData(LS_KEYS.USER);
setUser(user);
if (!user?.token) {
router.push("/");
void router.push("/");
} else if (key) {
if (justSignedUp()) {
setOpenRecoveryKey(true);
setLoading(false);
} else {
router.push(appHomeRoute);
void router.push(appHomeRoute);
}
} else if (keyAttributes?.encryptedKey) {
router.push(PAGES.CREDENTIALS);
void router.push(PAGES.CREDENTIALS);
} else {
setToken(user.token);
setLoading(false);
}
};
main();
void main();
appContext.showNavBar(true);
}, []);
@@ -106,7 +106,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
open={openRecoveryKey}
onClose={() => {
setOpenRecoveryKey(false);
router.push(appHomeRoute);
void router.push(appHomeRoute);
}}
showMiniDialog={showMiniDialog}
/>

View File

@@ -21,14 +21,14 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
void customAPIHost().then(setHost);
const user = getData(LS_KEYS.USER);
if (user?.email) {
router.push(PAGES.VERIFY);
void router.push(PAGES.VERIFY);
}
setLoading(false);
showNavBar(true);
}, []);
const signUp = () => {
router.push(PAGES.SIGNUP);
void router.push(PAGES.SIGNUP);
};
return loading ? (

View File

@@ -32,10 +32,8 @@ const Page: React.FC<PageProps> = () => {
const response = searchParams.get("response");
if (!passkeySessionID || !response) return;
saveCredentialsAndNavigateTo(passkeySessionID, response).then(
(slug: string) => {
router.push(slug);
},
void saveCredentialsAndNavigateTo(passkeySessionID, response).then(
(slug: string) => router.push(slug),
);
}, []);

View File

@@ -43,19 +43,19 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const keyAttributes: KeyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);
const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);
if (!user?.email) {
router.push("/");
void router.push("/");
return;
}
if (!user?.encryptedToken && !user?.token) {
sendOtt(user.email);
void sendOtt(user.email);
stashRedirect(PAGES.RECOVER);
router.push(PAGES.VERIFY);
void router.push(PAGES.VERIFY);
return;
}
if (!keyAttributes) {
router.push(PAGES.GENERATE);
void router.push(PAGES.GENERATE);
} else if (key) {
router.push(appHomeRoute);
void router.push(appHomeRoute);
} else {
setKeyAttributes(keyAttributes);
}
@@ -91,7 +91,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
await decryptAndStoreToken(keyAttr, masterKey);
setData(LS_KEYS.SHOW_BACK_BUTTON, { value: false });
router.push(PAGES.CHANGE_PASSWORD);
void router.push(PAGES.CHANGE_PASSWORD);
} catch (e) {
log.error("password recovery failed", e);
setFieldError(t("INCORRECT_RECOVERY_KEY"));

View File

@@ -21,14 +21,14 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
void customAPIHost().then(setHost);
const user = getData(LS_KEYS.USER);
if (user?.email) {
router.push(PAGES.VERIFY);
void router.push(PAGES.VERIFY);
}
setLoading(false);
showNavBar(true);
}, []);
const login = () => {
router.push(PAGES.LOGIN);
void router.push(PAGES.LOGIN);
};
return (

View File

@@ -57,12 +57,12 @@ const Page: React.FC<RecoverPageProps> = ({ appContext, twoFactorType }) => {
const user = getData(LS_KEYS.USER);
const sid = user.passkeySessionID || user.twoFactorSessionID;
if (!user || !user.email || !sid) {
router.push("/");
void router.push("/");
} else if (
!(user.isTwoFactorEnabled || user.isTwoFactorEnabledPasskey) &&
(user.encryptedToken || user.token)
) {
router.push(PAGES.GENERATE);
void router.push(PAGES.GENERATE);
} else {
setSessionID(sid);
}
@@ -81,6 +81,7 @@ const Page: React.FC<RecoverPageProps> = ({ appContext, twoFactorType }) => {
} catch (e) {
if (
e instanceof ApiError &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
e.httpStatusCode === HttpStatusCode.NotFound
) {
logout();
@@ -91,7 +92,7 @@ const Page: React.FC<RecoverPageProps> = ({ appContext, twoFactorType }) => {
}
}
};
main();
void main();
}, []);
const recover: SingleInputFormProps["callback"] = async (
@@ -133,7 +134,7 @@ const Page: React.FC<RecoverPageProps> = ({ appContext, twoFactorType }) => {
isTwoFactorEnabled: false,
});
setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);
router.push(PAGES.CREDENTIALS);
void router.push(PAGES.CREDENTIALS);
} catch (e) {
log.error("two factor recovery failed", e);
setFieldError(t("INCORRECT_RECOVERY_KEY"));

View File

@@ -41,7 +41,7 @@ const Page: React.FC<PageProps> = () => {
log.error("failed to get two factor setup code", e);
}
};
main();
void main();
}, []);
const onSubmit: VerifyTwoFactorCallback = async (
@@ -57,7 +57,7 @@ const Page: React.FC<PageProps> = () => {
...getData(LS_KEYS.USER),
isTwoFactorEnabled: true,
});
router.push(appHomeRoute);
void router.push(appHomeRoute);
};
return (

View File

@@ -36,17 +36,17 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const main = async () => {
const user: User = getData(LS_KEYS.USER);
if (!user?.email || !user.twoFactorSessionID) {
router.push("/");
void router.push("/");
} else if (
!user.isTwoFactorEnabled &&
(user.encryptedToken || user.token)
) {
router.push(PAGES.CREDENTIALS);
void router.push(PAGES.CREDENTIALS);
} else {
setSessionID(user.twoFactorSessionID);
}
};
main();
void main();
}, []);
const onSubmit: VerifyTwoFactorCallback = async (otp) => {
@@ -60,10 +60,11 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
id,
});
setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes!);
router.push(unstashRedirect() ?? PAGES.CREDENTIALS);
void router.push(unstashRedirect() ?? PAGES.CREDENTIALS);
} catch (e) {
if (
e instanceof ApiError &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
e.httpStatusCode === HttpStatusCode.NotFound
) {
logout();

View File

@@ -60,12 +60,12 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const redirect = await redirectionIfNeeded(user);
if (redirect) {
router.push(redirect);
void router.push(redirect);
} else {
setEmail(user.email);
}
};
main();
void main();
showNavBar(true);
}, []);
@@ -108,7 +108,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
isTwoFactorEnabled: true,
});
setIsFirstLogin(true);
router.push(PAGES.TWO_FACTOR_VERIFY);
void router.push(PAGES.TWO_FACTOR_VERIFY);
} else {
await setLSUser({
email,
@@ -134,20 +134,22 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
await configureSRP(srpSetupAttributes);
}
}
localForage.clear();
await localForage.clear();
setIsFirstLogin(true);
const redirectURL = unstashRedirect();
if (keyAttributes?.encryptedKey) {
clearKeys();
router.push(redirectURL ?? PAGES.CREDENTIALS);
void router.push(redirectURL ?? PAGES.CREDENTIALS);
} else {
router.push(redirectURL ?? PAGES.GENERATE);
void router.push(redirectURL ?? PAGES.GENERATE);
}
}
} catch (e) {
if (e instanceof ApiError) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
if (e?.httpStatusCode === HttpStatusCode.Unauthorized) {
setFieldError(t("INVALID_CODE"));
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
} else if (e?.httpStatusCode === HttpStatusCode.Gone) {
setFieldError(t("EXPIRED_CODE"));
}