From 22354823457d2f99f7dc3eb652440d92083d3f68 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 2 Jul 2025 11:00:28 +0530 Subject: [PATCH] Conv --- web/apps/photos/src/pages/gallery.tsx | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx index 93b0ebae30..ef7db03a6e 100644 --- a/web/apps/photos/src/pages/gallery.tsx +++ b/web/apps/photos/src/pages/gallery.tsx @@ -33,6 +33,7 @@ import { haveCredentialsInSession, masterKeyFromSession, } from "ente-base/session"; +import { getAuthToken } from "ente-base/token"; import { FullScreenDropZone } from "ente-gallery/components/FullScreenDropZone"; import { type UploadTypeSelectorIntent } from "ente-gallery/components/Upload"; import { type Collection } from "ente-media/collection"; @@ -110,7 +111,6 @@ import { import { usePhotosAppContext } from "ente-new/photos/types/context"; import { getData } from "ente-shared/storage/localStorage"; import { - getToken, isFirstLogin, justSignedUp, setIsFirstLogin, @@ -277,23 +277,30 @@ const Page: React.FC = () => { const router = useRouter(); useEffect(() => { - const token = getToken(); - if (!haveCredentialsInSession() || !token) { - stashRedirect("/gallery"); - router.push("/"); - return; - } - preloadImage("/images/subscription-card-background"); - const electron = globalThis.electron; let syncIntervalID: ReturnType | undefined; void (async () => { + if (!haveCredentialsInSession() || !(await getAuthToken())) { + // If we don't have master key or auth token, reauthenticate. + stashRedirect("/gallery"); + router.push("/"); + return; + } + if (!(await validateKey())) { + // If we have credentials but they can't be decrypted, reset. + // + // This code is never expected to run, it is only kept as a + // safety valve. logout(); return; } + + // We are logged in and everything looks fine. Proceed with page + // load initialization. initSettings(); + preloadImage("/images/subscription-card-background"); await initUserDetailsOrTriggerPull(); setupSelectAllKeyBoardShortcutHandler(); dispatch({ type: "showAll" });