π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Global handling of in-flight requests during logout
Manav Rathi7cd54f481582
diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsxindex b8cb12239d..9b07368b3b 100644--- a/web/apps/auth/src/pages/_app.tsx+++ b/web/apps/auth/src/pages/_app.tsx@@ -32,7 +32,13 @@ import { ThemeProvider } from "@mui/material/styles";import { t } from "i18next";import type { AppProps } from "next/app";import { useRouter } from "next/router";-import React, { createContext, useContext, useEffect, useState } from "react";+import React, {+ createContext,+ useCallback,+ useContext,+ useEffect,+ useState,+} from "react";import "../../public/css/global.css";@@ -105,9 +111,9 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {const somethingWentWrong = () =>showMiniDialog(genericErrorDialogAttributes());- const logout = () => {- void accountLogout().then(() => router.push("/"));- };+ const logout = useCallback(() => {+ void accountLogout().then(() => window.location.replace("/"));+ }, []);const appContext = {logout,diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 7a1582b8e4..c37bbe045b 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -207,9 +207,7 @@ export default function App({ Component, pageProps }: AppProps) {showMiniDialog(genericErrorDialogAttributes());}, []);- const logout = useCallback(() => {- void photosLogout().then(() => router.push("/"));- }, [router]);+ const logout = useCallback(() => void photosLogout(), []);const appContext = {showNavBar,diff --git a/web/apps/photos/src/services/logout.ts b/web/apps/photos/src/services/logout.tsindex 517323771c..3dbc63e6dd 100644--- a/web/apps/photos/src/services/logout.ts+++ b/web/apps/photos/src/services/logout.ts@@ -1,4 +1,7 @@-import { accountLogout } from "@/accounts/services/logout";+import {+ accountLogout,+ logoutClearStateAgain,+} from "@/accounts/services/logout";import log from "@/base/log";import { resetUploadState } from "@/gallery/upload";import DownloadManager from "@/new/photos/services/download";@@ -90,4 +93,14 @@ export const photosLogout = async () => {ignoreError("electron", e);}}++ // Clear the DB again to discard any in-flight completions that might've+ // happened since we started.++ await logoutClearStateAgain();++ // Do a full reload to discard any in-flight requests that might still+ // remain.++ window.location.replace("/");};diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.tsindex aa1b2a1d3e..e70a61ce6b 100644--- a/web/packages/new/photos/services/settings.ts+++ b/web/packages/new/photos/services/settings.ts@@ -69,15 +69,7 @@ const defaultSettings = (): Settings => ({* This entire object will be reset on logout.*/class SettingsState {- /**- * An arbitrary token to identify the current login.- *- * It is used to discard stale completions.- */- id: number;-constructor() {- this.id = Math.random();this.settingsSnapshot = defaultSettings();}@@ -117,12 +109,7 @@ export const logoutSettings = () => {* lookup. Then use the results to update our in memory state if needed.*/export const syncSettings = async () => {- const id = _state.id;const jsonString = await fetchFeatureFlags().then((res) => res.text());- if (_state.id != id) {- log.info("Discarding on logout");- return;- }saveRemoteFeatureFlagsJSONString(jsonString);syncSettingsSnapshotWithLocalStorage();};diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.tsindex 3663e4c580..f9549c5e24 100644--- a/web/packages/new/photos/services/user.ts+++ b/web/packages/new/photos/services/user.ts@@ -1,6 +1,5 @@import { authenticatedRequestHeaders, ensureOk } from "@/base/http";import { getKV, setKV } from "@/base/kv";-import log from "@/base/log";import { apiURL } from "@/base/origins";import { z } from "zod";import { FamilyData } from "./family";@@ -43,17 +42,6 @@ export type UserDetails = z.infer<typeof UserDetails>;* This entire object will be reset on logout.*/class UserState {- /**- * An arbitrary token to identify the current login.- *- * It is used to discard stale completions.- */- id: number;-- constructor() {- this.id = Math.random();- }-/*** Subscriptions to {@link UserDetails} updates attached using* {@link userDetailsSubscribe}.@@ -129,12 +117,7 @@ const setUserDetailsSnapshot = (snapshot: UserDetails) => {* subsequent lookup, and also update our in-memory snapshots.*/export const syncUserDetails = async () => {- const id = _state.id;const userDetails = await getUserDetailsV2();- if (_state.id != id) {- log.info("Discarding on logout");- return;- }await setKV("userDetails", userDetails);setUserDetailsSnapshot(userDetails);};