From e4e75b573f467bf68fec405d8165260a27db1728 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 21 Jun 2024 13:23:21 +0530 Subject: [PATCH] Reduce indentation --- web/packages/accounts/pages/credentials.tsx | 57 +++++++++++---------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx index 227c513bfd..8806d1db17 100644 --- a/web/packages/accounts/pages/credentials.tsx +++ b/web/packages/accounts/pages/credentials.tsx @@ -78,6 +78,32 @@ const Page: React.FC = ({ appContext }) => { [setDialogBoxAttributesV2, logout], ); + const validateSession = useCallback(async () => { + try { + const session = await checkSessionValidity(); + switch (session.status) { + case "invalid": + showSessionExpiredDialog(); + break; + case "valid": + if (session.updatedKeyAttributes) { + setData( + LS_KEYS.KEY_ATTRIBUTES, + session.updatedKeyAttributes, + ); + // This should be a rare occurence, instead of building + // the scaffolding to update all the in-memory state, + // just reload everything. + router.reload(); + } + } + } catch (e) { + // Ignore errors since we shouldn't be logging the user out for + // potentially transient issues. + log.warn("Ignoring error when determining session validity", e); + } + }, [showSessionExpiredDialog, router]); + useEffect(() => { const main = async () => { const user: User = getData(LS_KEYS.USER); @@ -118,33 +144,8 @@ const Page: React.FC = ({ appContext }) => { ); if (token) { - void checkSessionValidity() - .then((session) => { - switch (session.status) { - case "invalid": - showSessionExpiredDialog(); - break; - case "valid": - if (session.updatedKeyAttributes) { - setData( - LS_KEYS.KEY_ATTRIBUTES, - session.updatedKeyAttributes, - ); - // This should be a rare occurence, instead of - // building the scaffolding to update all the - // in-memory state, just reload everything. - router.reload(); - } - } - }) - .catch((e) => { - // Ignore errors since we shouldn't be logging the user out for - // potentially transient issues. - log.warn( - "Ignoring error when determining session validity", - e, - ); - }); + // Let it validate without blocking the rest of the flow. + void validateSession(); } if (kekEncryptedAttributes && keyAttributes) { @@ -185,6 +186,8 @@ const Page: React.FC = ({ appContext }) => { main(); appContext.showNavBar(true); }, []); + // TODO: ^ validateSession is a dependency, but add that only after we've + // wrapped items from the callback (like logout) in useCallback too. const getKeyAttributes: VerifyMasterPasswordFormProps["getKeyAttributes"] = async (kek: string) => {