Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Update

Manav Rathi337c25b670e8
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index baa3f357e9..960f01de0b 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -4,9 +4,9 @@ import { CssBaseline, Typography } from "@mui/material";
import { styled, ThemeProvider } from "@mui/material/styles";
import { useNotification } from "components/utils/hooks-app";
import {
- getData,
isLocalStorageAndIndexedDBMismatch,
savedLocalUser,
+ savedPartialLocalUser,
} from "ente-accounts/services/accounts-db";
import { isDesktop, staticAppTitle } from "ente-base/app";
import { CenteredRow } from "ente-base/components/containers";
@@ -127,11 +127,11 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
useEffect(() => {
const query = new URLSearchParams(window.location.search);
const needsFamilyRedirect = query.get("redirect") == "families";
- if (needsFamilyRedirect && getData("user")?.token)
+ if (needsFamilyRedirect && savedPartialLocalUser()?.token)
redirectToFamilyPortal();
router.events.on("routeChangeStart", () => {
- if (needsFamilyRedirect && getData("user")?.token) {
+ if (needsFamilyRedirect && savedPartialLocalUser()?.token) {
redirectToFamilyPortal();
// https://github.com/vercel/next.js/issues/2476#issuecomment-573460710
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 46579debcf..4d8b4a2f56 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -17,10 +17,10 @@ import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/d
import {
getAndClearIsFirstLogin,
getAndClearJustSignedUp,
- getData,
} from "ente-accounts/services/accounts-db";
import { stashRedirect } from "ente-accounts/services/redirect";
import { isSessionInvalid } from "ente-accounts/services/session";
+import { ensureLocalUser } from "ente-accounts/services/user";
import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";
import { NavbarBase } from "ente-base/components/Navbar";
import { SingleInputDialog } from "ente-base/components/SingleInputDialog";
@@ -318,13 +318,10 @@ const Page: React.FC = () => {
}
// Initialize the reducer.
- const user = getData("user");
- // TODO: Pass entire snapshot to reducer?
- const familyData = userDetailsSnapshot()?.familyData;
dispatch({
type: "mount",
- user,
- familyData,
+ user: ensureLocalUser(),
+ familyData: userDetailsSnapshot()?.familyData,
collections: await savedCollections(),
collectionFiles: await savedCollectionFiles(),
trashItems: await savedTrashItems(),
diff --git a/web/apps/photos/src/pages/index.tsx b/web/apps/photos/src/pages/index.tsx
index 291314daa5..3ac7b0d771 100644
--- a/web/apps/photos/src/pages/index.tsx
+++ b/web/apps/photos/src/pages/index.tsx
@@ -1,7 +1,7 @@
import { Box, Stack, Typography, styled } from "@mui/material";
import { LoginContents } from "ente-accounts/components/LoginContents";
import { SignUpContents } from "ente-accounts/components/SignUpContents";
-import { getData } from "ente-accounts/services/accounts-db";
+import { savedPartialLocalUser } from "ente-accounts/services/accounts-db";
import { CenteredFill, CenteredRow } from "ente-base/components/containers";
import { EnteLogo } from "ente-base/components/EnteLogo";
import { ActivityIndicator } from "ente-base/components/mui/ActivityIndicator";
@@ -34,53 +34,44 @@ const Page: React.FC = () => {
);
useEffect(() => {
- refreshHost();
- const currentURL = new URL(window.location.href);
- const albumsURL = new URL(albumsAppOrigin());
- currentURL.pathname = router.pathname;
- if (
- currentURL.host === albumsURL.host &&
- currentURL.pathname != "/shared-albums"
- ) {
- handleAlbumsRedirect(currentURL);
- } else {
- handleNormalRedirect();
- }
- }, [refreshHost]);
-
- const handleAlbumsRedirect = async (currentURL: URL) => {
- const end = currentURL.hash.lastIndexOf("&");
- const hash = currentURL.hash.slice(1, end !== -1 ? end : undefined);
- await router.replace({
- pathname: "/shared-albums",
- search: currentURL.search,
- hash: hash,
- });
- await ensureIndexedDBAccess();
- };
-
- const handleNormalRedirect = async () => {
- const user = getData("user");
- await updateSessionFromElectronSafeStorageIfNeeded();
- if (await haveAuthenticatedSession()) {
- await router.push("/gallery");
- } else if (user?.email) {
- await router.push("/verify");
- }
- await ensureIndexedDBAccess();
- };
-
- const ensureIndexedDBAccess = useCallback(async () => {
- if (!(await canAccessIndexedDB())) {
- showMiniDialog({
- title: t("error"),
- message: t("local_storage_not_accessible"),
- nonClosable: true,
- cancel: false,
- });
- }
- setLoading(false);
- }, [showMiniDialog]);
+ void (async () => {
+ refreshHost();
+ const currentURL = new URL(window.location.href);
+ const albumsURL = new URL(albumsAppOrigin());
+ currentURL.pathname = router.pathname;
+ if (
+ currentURL.host == albumsURL.host &&
+ currentURL.pathname != "/shared-albums"
+ ) {
+ const end = currentURL.hash.lastIndexOf("&");
+ const hash = currentURL.hash.slice(
+ 1,
+ end !== -1 ? end : undefined,
+ );
+ await router.replace({
+ pathname: "/shared-albums",
+ search: currentURL.search,
+ hash: hash,
+ });
+ } else {
+ await updateSessionFromElectronSafeStorageIfNeeded();
+ if (await haveAuthenticatedSession()) {
+ await router.push("/gallery");
+ } else if (savedPartialLocalUser()?.email) {
+ await router.push("/verify");
+ }
+ }
+ if (!(await canAccessIndexedDB())) {
+ showMiniDialog({
+ title: t("error"),
+ message: t("local_storage_not_accessible"),
+ nonClosable: true,
+ cancel: false,
+ });
+ }
+ setLoading(false);
+ })();
+ }, [showMiniDialog, router, refreshHost]);
return (
<TappableContainer onMaybeChangeHost={refreshHost}>