π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update to use InMemoryStore for redirectURL
Abhinav75da4d125e37
diff --git a/apps/photos/src/pages/auth/index.tsx b/apps/photos/src/pages/auth/index.tsxindex 01811201cd..8f139d3a9c 100644--- a/apps/photos/src/pages/auth/index.tsx+++ b/apps/photos/src/pages/auth/index.tsx@@ -11,6 +11,7 @@ import AuthNavbar from 'components/pages/auth/Navbar';import { t } from 'i18next';import EnteSpinner from 'components/EnteSpinner';import { VerticallyCentered } from 'components/Container';+import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';const AuthenticatorCodesPage = () => {const appContext = useContext(AppContext);@@ -26,7 +27,7 @@ const AuthenticatorCodesPage = () => {setCodes(res);} catch (err) {if (err.message === CustomError.KEY_MISSING) {- appContext.setRedirectURL(PAGES.AUTH);+ InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.AUTH);router.push(PAGES.ROOT);} else {// do not log errorsdiff --git a/apps/photos/src/pages/credentials/index.tsx b/apps/photos/src/pages/credentials/index.tsxindex a4ff000db3..66e72dc2b4 100644--- a/apps/photos/src/pages/credentials/index.tsx+++ b/apps/photos/src/pages/credentials/index.tsx@@ -49,6 +49,7 @@ import { addLocalLog } from 'utils/logging';import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';import { B64EncryptionResult } from 'types/crypto';import { CustomError } from 'utils/error';+import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';export default function Credentials() {const router = useRouter();@@ -213,8 +214,8 @@ export default function Credentials() {} catch (e) {logError(e, 'migrate to srp failed');}- const redirectURL = appContext.redirectURL;- appContext.setRedirectURL(null);+ const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL);+ InMemoryStore.delete(MS_KEYS.REDIRECT_URL);const appName = getAppName();if (appName === APPS.AUTH) {router.push(PAGES.AUTH);diff --git a/apps/photos/src/pages/deduplicate/index.tsx b/apps/photos/src/pages/deduplicate/index.tsxindex 93e50fbb18..a611ae673c 100644--- a/apps/photos/src/pages/deduplicate/index.tsx+++ b/apps/photos/src/pages/deduplicate/index.tsx@@ -29,6 +29,7 @@ import EnteSpinner from 'components/EnteSpinner';import { VerticallyCentered } from 'components/Container';import Typography from '@mui/material/Typography';import useMemoSingleThreaded from 'hooks/useMemoSingleThreaded';+import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';export const DeduplicateContext = createContext<DeduplicateContextType>(DefaultDeduplicateContext@@ -39,13 +40,8 @@ export const Info = styled('div')``;export default function Deduplicate() {- const {- setDialogMessage,- startLoading,- finishLoading,- showNavBar,- setRedirectURL,- } = useContext(AppContext);+ const { setDialogMessage, startLoading, finishLoading, showNavBar } =+ useContext(AppContext);const [duplicateFiles, setDuplicateFiles] = useState<EnteFile[]>(null);const [clubSameTimeFilesOnly, setClubSameTimeFilesOnly] = useState(false);const [fileSizeMap, setFileSizeMap] = useState(new Map<number, number>());@@ -63,7 +59,7 @@ export default function Deduplicate() {useEffect(() => {const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);if (!key) {- setRedirectURL(router.asPath);+ InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.DEDUPLICATE);router.push(PAGES.ROOT);return;}diff --git a/apps/photos/src/pages/gallery/index.tsx b/apps/photos/src/pages/gallery/index.tsxindex c7eb48906e..e308301cd5 100644--- a/apps/photos/src/pages/gallery/index.tsx+++ b/apps/photos/src/pages/gallery/index.tsx@@ -120,6 +120,7 @@ import { getSessionExpiredMessage } from 'utils/ui';import { syncEntities } from 'services/entityService';import { constructUserIDToEmailMap } from 'services/collectionService';import { getLocalFamilyData } from 'utils/user/family';+import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';export const DeadCenter = styled('div')`flex: 1;@@ -284,7 +285,7 @@ export default function Gallery() {appContext.showNavBar(true);const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);if (!key) {- appContext.setRedirectURL(router.asPath);+ InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.GALLERY);router.push(PAGES.ROOT);return;}diff --git a/apps/photos/src/pages/recover/index.tsx b/apps/photos/src/pages/recover/index.tsxindex 1fa64d97d8..8a001f03dc 100644--- a/apps/photos/src/pages/recover/index.tsx+++ b/apps/photos/src/pages/recover/index.tsx@@ -19,6 +19,7 @@ import FormPaperFooter from 'components/Form/FormPaper/Footer';import LinkButton from 'components/pages/gallery/LinkButton';import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';import { sendOtt } from 'services/userService';+import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';const bip39 = require('bip39');// mobile client library only supports english.bip39.setDefaultWordlist('english');@@ -39,7 +40,7 @@ export default function Recover() {}if (!user?.encryptedToken && !user?.token) {sendOtt(user.email);- appContext.setRedirectURL(PAGES.RECOVER);+ InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.RECOVER);router.push(PAGES.VERIFY);return;}diff --git a/apps/photos/src/pages/two-factor/verify/index.tsx b/apps/photos/src/pages/two-factor/verify/index.tsxindex 9d870a6659..85cb0b4708 100644--- a/apps/photos/src/pages/two-factor/verify/index.tsx+++ b/apps/photos/src/pages/two-factor/verify/index.tsx@@ -2,7 +2,7 @@ import VerifyTwoFactor, {VerifyTwoFactorCallback,} from 'components/TwoFactor/VerifyForm';import router from 'next/router';-import { useContext, useEffect, useState } from 'react';+import { useEffect, useState } from 'react';import { logoutUser, verifyTwoFactor } from 'services/userService';import { PAGES } from 'constants/pages';import { User } from 'types/user';@@ -14,10 +14,9 @@ import FormPaper from 'components/Form/FormPaper';import FormTitle from 'components/Form/FormPaper/Title';import FormPaperFooter from 'components/Form/FormPaper/Footer';import { VerticallyCentered } from 'components/Container';-import { AppContext } from 'pages/_app';+import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';export default function Home() {- const appContext = useContext(AppContext);const [sessionID, setSessionID] = useState('');useEffect(() => {@@ -49,8 +48,8 @@ export default function Home() {id,});setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);- const redirectURL = appContext.redirectURL;- appContext.setRedirectURL(null);+ const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL);+ InMemoryStore.delete(MS_KEYS.REDIRECT_URL);router.push(redirectURL ?? PAGES.CREDENTIALS);} catch (e) {if (e.status === 404) {diff --git a/apps/photos/src/pages/verify/index.tsx b/apps/photos/src/pages/verify/index.tsxindex 94cb833c1a..8de5b2e89b 100644--- a/apps/photos/src/pages/verify/index.tsx+++ b/apps/photos/src/pages/verify/index.tsx@@ -32,6 +32,7 @@ import SingleInputForm, {} from 'components/SingleInputForm';import EnteSpinner from 'components/EnteSpinner';import { VerticallyCentered } from 'components/Container';+import InMemoryStore, { MS_KEYS } from 'services/InMemoryStore';export default function Verify() {const [email, setEmail] = useState('');@@ -111,8 +112,8 @@ export default function Verify() {}clearFiles();setIsFirstLogin(true);- const redirectURL = appContext.redirectURL;- appContext.setRedirectURL(null);+ const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL);+ InMemoryStore.delete(MS_KEYS.REDIRECT_URL);if (keyAttributes?.encryptedKey) {clearKeys();router.push(redirectURL ?? PAGES.CREDENTIALS);diff --git a/apps/photos/src/services/InMemoryStore.ts b/apps/photos/src/services/InMemoryStore.tsindex 71159eb22d..82e0155a68 100644--- a/apps/photos/src/services/InMemoryStore.ts+++ b/apps/photos/src/services/InMemoryStore.ts@@ -17,6 +17,10 @@ class InMemoryStore {this.store.set(key, value);}+ delete(key: MS_KEYS) {+ this.store.delete(key);+ }+has(key: MS_KEYS) {return this.store.has(key);}