π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update page home redirection logic
Abhinav9ad0954a3799
diff --git a/packages/accounts/components/ChangeEmail.tsx b/packages/accounts/components/ChangeEmail.tsxindex 09c0bd9804..e2055fdb24 100644--- a/packages/accounts/components/ChangeEmail.tsx+++ b/packages/accounts/components/ChangeEmail.tsx@@ -2,10 +2,8 @@ import { Formik, FormikHelpers } from 'formik';import React, { useRef, useState } from 'react';import * as Yup from 'yup';import SubmitButton from '@ente/shared/components/SubmitButton';-import router from 'next/router';import { changeEmail, sendOTTForEmailChange } from '@ente/accounts/api/user';import { getData, LS_KEYS, setData } from '@ente/shared/storage/localStorage';-import { PAGES } from '@ente/accounts/constants/pages';import { Alert, Box, TextField } from '@mui/material';import { VerticallyCentered } from '@ente/shared/components/Container';import LinkButton from '@ente/shared/components/LinkButton';@@ -13,14 +11,15 @@ import FormPaperFooter from '@ente/shared/components/Form/FormPaper/Footer';import { sleep } from '@ente/shared/utils';import { Trans } from 'react-i18next';import { t } from 'i18next';-import { APPS } from '@ente/shared/apps/constants';+import { APP_HOMES } from '@ente/shared/apps/constants';+import { PageProps } from '@ente/shared/apps/types';interface formValues {email: string;ott?: string;}-function ChangeEmailForm({ appName }: { appName: string }) {+function ChangeEmailForm({ appName, router }: PageProps) {const [loading, setLoading] = useState(false);const [ottInputVisible, setShowOttInputVisibility] = useState(false);const ottInputRef = useRef(null);@@ -66,11 +65,7 @@ function ChangeEmailForm({ appName }: { appName: string }) {};const goToApp = () => {- if (appName === APPS.AUTH) {- router.push(PAGES.AUTH);- } else {- router.push(PAGES.GALLERY);- }+ router.push(APP_HOMES.get(appName));};return (diff --git a/packages/accounts/constants/pages.ts b/packages/accounts/constants/pages.tsindex 0853a915b7..6afa97862f 100644--- a/packages/accounts/constants/pages.ts+++ b/packages/accounts/constants/pages.ts@@ -11,7 +11,5 @@ export enum PAGES {TWO_FACTOR_VERIFY = '/two-factor/verify',TWO_FACTOR_RECOVER = '/two-factor/recover',VERIFY = '/verify',- GALLERY = '/gallery',- AUTH = '/auth',SHARED_ALBUMS = '/shared-albums',}diff --git a/packages/accounts/pages/change-email.tsx b/packages/accounts/pages/change-email.tsxindex 75ab627643..04106ecf7a 100644--- a/packages/accounts/pages/change-email.tsx+++ b/packages/accounts/pages/change-email.tsx@@ -9,7 +9,7 @@ import FormPaper from '@ente/shared/components/Form/FormPaper';import FormPaperTitle from '@ente/shared/components/Form/FormPaper/Title';import { PageProps } from '@ente/shared/apps/types';-function ChangeEmailPage({ router, appName }: PageProps) {+function ChangeEmailPage({ router, appName, appContext }: PageProps) {useEffect(() => {const user = getData(LS_KEYS.USER);if (!user?.token) {@@ -21,7 +21,11 @@ function ChangeEmailPage({ router, appName }: PageProps) {<VerticallyCentered><FormPaper><FormPaperTitle>{t('CHANGE_EMAIL')}</FormPaperTitle>- <ChangeEmailForm appName={appName} />+ <ChangeEmailForm+ router={router}+ appName={appName}+ appContext={appContext}+ /></FormPaper></VerticallyCentered>);diff --git a/packages/accounts/pages/change-password.tsx b/packages/accounts/pages/change-password.tsxindex d838437f7e..775fbbe54d 100644--- a/packages/accounts/pages/change-password.tsx+++ b/packages/accounts/pages/change-password.tsx@@ -28,7 +28,7 @@ import FormPaper from '@ente/shared/components/Form/FormPaper';import FormPaperFooter from '@ente/shared/components/Form/FormPaper/Footer';import FormPaperTitle from '@ente/shared/components/Form/FormPaper/Title';import ComlinkCryptoWorker from '@ente/shared/crypto';-import { APPS } from '@ente/shared/apps/constants';+import { APP_HOMES } from '@ente/shared/apps/constants';import {convertBufferToBase64,convertBase64ToBuffer,@@ -121,11 +121,7 @@ export default function ChangePassword({ appName, router }: PageProps) {const redirectToAppHome = () => {setData(LS_KEYS.SHOW_BACK_BUTTON, { value: true });- if (appName === APPS.AUTH) {- router.push(PAGES.AUTH);- } else {- router.push(PAGES.GALLERY);- }+ router.push(APP_HOMES.get(appName));};return (diff --git a/packages/accounts/pages/credentials.tsx b/packages/accounts/pages/credentials.tsxindex 7e05687790..355136f41d 100644--- a/packages/accounts/pages/credentials.tsx+++ b/packages/accounts/pages/credentials.tsx@@ -50,7 +50,7 @@ import { B64EncryptionResult } from '@ente/shared/crypto/types';import { CustomError } from '@ente/shared/error';import InMemoryStore, { MS_KEYS } from '@ente/shared/storage/InMemoryStore';import { PageProps } from '@ente/shared/apps/types';-import { APPS } from '@ente/shared/apps/constants';+import { APP_HOMES } from '@ente/shared/apps/constants';import { logError } from '@ente/shared/sentry';import ElectronAPIs from '@ente/shared/electron';@@ -64,13 +64,6 @@ export default function Credentials({const [user, setUser] = useState<User>();useEffect(() => {- if (appName === APPS.AUTH) {- router.prefetch(PAGES.AUTH);- } else if (appName === APPS.PHOTOS) {- router.prefetch(PAGES.GALLERY);- } else {- router.prefetch(PAGES.SHARED_ALBUMS);- }const main = async () => {const user: User = getData(LS_KEYS.USER);if (!user?.email) {@@ -90,11 +83,7 @@ export default function Credentials({}}if (key) {- if (appName === APPS.AUTH) {- router.push(PAGES.AUTH);- } else {- router.push(PAGES.GALLERY);- }+ router.push(APP_HOMES.get(appName));return;}const kekEncryptedAttributes: B64EncryptionResult = getKey(@@ -236,11 +225,7 @@ export default function Credentials({}const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL);InMemoryStore.delete(MS_KEYS.REDIRECT_URL);- if (appName === APPS.AUTH) {- router.push(PAGES.AUTH);- } else {- router.push(redirectURL ?? PAGES.GALLERY);- }+ router.push(APP_HOMES.get(redirectURL ?? appName));} catch (e) {logError(e, 'useMasterPassword failed');}diff --git a/packages/accounts/pages/generate.tsx b/packages/accounts/pages/generate.tsxindex 1f885d3373..d293fe7ad5 100644--- a/packages/accounts/pages/generate.tsx+++ b/packages/accounts/pages/generate.tsx@@ -25,7 +25,7 @@ import { logError } from '@ente/shared/sentry';import { KeyAttributes, User } from '@ente/shared/user/types';import FormPaper from '@ente/shared/components/Form/FormPaper';import FormTitle from '@ente/shared/components/Form/FormPaper/Title';-import { APPS } from '@ente/shared/apps/constants';+import { APP_HOMES } from '@ente/shared/apps/constants';import FormPaperFooter from '@ente/shared/components/Form/FormPaper/Footer';import LinkButton from '@ente/shared/components/LinkButton';import { PageProps } from '@ente/shared/apps/types';@@ -40,8 +40,6 @@ export default function Generate({ router, appContext, appName }: PageProps) {const keyAttributes: KeyAttributes = getData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES);- router.prefetch(PAGES.GALLERY);- router.prefetch(PAGES.CREDENTIALS);const user: User = getData(LS_KEYS.USER);setUser(user);if (!user?.token) {@@ -51,11 +49,7 @@ export default function Generate({ router, appContext, appName }: PageProps) {setRecoveryModalView(true);setLoading(false);} else {- if (appName === APPS.AUTH) {- router.push(PAGES.AUTH);- } else {- router.push(PAGES.GALLERY);- }+ router.push(APP_HOMES.get(appName));}} else if (keyAttributes?.encryptedKey) {router.push(PAGES.CREDENTIALS);@@ -100,11 +94,7 @@ export default function Generate({ router, appContext, appName }: PageProps) {show={recoverModalView}onHide={() => {setRecoveryModalView(false);- if (appName === APPS.AUTH) {- router.push(PAGES.AUTH);- } else {- router.push(PAGES.GALLERY);- }+ router.push(APP_HOMES.get(appName));}}somethingWentWrong={() => null}/>diff --git a/packages/accounts/pages/recover.tsx b/packages/accounts/pages/recover.tsxindex 46f198856c..997e4205df 100644--- a/packages/accounts/pages/recover.tsx+++ b/packages/accounts/pages/recover.tsx@@ -22,7 +22,7 @@ import { sendOtt } from '@ente/accounts/api/user';import InMemoryStore, { MS_KEYS } from '@ente/shared/storage/InMemoryStore';import { PageProps } from '@ente/shared/apps/types';import { logError } from '@ente/shared/sentry';-import { APPS } from '@ente/shared/apps/constants';+import { APP_HOMES } from '@ente/shared/apps/constants';const bip39 = require('bip39');// mobile client library only supports english.bip39.setDefaultWordlist('english');@@ -31,7 +31,6 @@ export default function Recover({ appContext, router, appName }: PageProps) {const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();useEffect(() => {- router.prefetch(PAGES.GALLERY);const user: User = getData(LS_KEYS.USER);const keyAttributes: KeyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);@@ -48,11 +47,7 @@ export default function Recover({ appContext, router, appName }: PageProps) {if (!keyAttributes) {router.push(PAGES.GENERATE);} else if (key) {- if (appName === APPS.AUTH) {- router.push(PAGES.AUTH);- } else {- router.push(PAGES.GALLERY);- }+ router.push(APP_HOMES.get(appName));} else {setKeyAttributes(keyAttributes);}diff --git a/packages/shared/apps/constants.ts b/packages/shared/apps/constants.tsindex 5916fdc425..4591e13a69 100644--- a/packages/shared/apps/constants.ts+++ b/packages/shared/apps/constants.ts@@ -1,6 +1,4 @@-// import { PAGES } from 'constants/pages';-// import { runningInBrowser } from 'utils/common';-// import { getAlbumsURL, getAuthURL } from 'utils/common/apiUtil';+import { AUTH_PAGES, PHOTOS_PAGES } from '../constants/pages';export enum APPS {PHOTOS = 'PHOTOS',@@ -25,3 +23,9 @@ export const APP_TITLES = new Map([[APPS.PHOTOS, 'Ente Photos'],[APPS.AUTH, 'Ente Auth'],]);++export const APP_HOMES = new Map([+ [APPS.ALBUMS, '/'],+ [APPS.PHOTOS, PHOTOS_PAGES.GALLERY],+ [APPS.AUTH, AUTH_PAGES.AUTH],+]);diff --git a/packages/shared/constants/pages.tsx b/packages/shared/constants/pages.tsxindex ae05d7aa81..71f01cee96 100644--- a/packages/shared/constants/pages.tsx+++ b/packages/shared/constants/pages.tsx@@ -19,7 +19,7 @@ export enum PHOTOS_PAGES {AUTH = '/auth',}-export enum LOCKER_PAGES {+export enum AUTH_PAGES {CHANGE_EMAIL = '/change-email',CHANGE_PASSWORD = '/change-password',CREDENTIALS = '/credentials',@@ -33,9 +33,5 @@ export enum LOCKER_PAGES {TWO_FACTOR_RECOVER = '/two-factor/recover',VERIFY = '/verify',ROOT = '/',- SHARED_ALBUMS = '/shared-albums',- // ML_DEBUG = '/ml-debug',- DEDUPLICATE = '/deduplicate',- // AUTH page is used to show (auth)enticator codesAUTH = '/auth',}