π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Validate in the other places where we request the password
Manav Rathic988c30910a8
diff --git a/web/apps/photos/src/components/AuthenticateUserModal.tsx b/web/apps/photos/src/components/AuthenticateUserModal.tsxindex 3e54a86c0a..e0762c3b1f 100644--- a/web/apps/photos/src/components/AuthenticateUserModal.tsx+++ b/web/apps/photos/src/components/AuthenticateUserModal.tsx@@ -1,5 +1,7 @@import log from "@/next/log";+import { checkSessionValidity } from "@ente/accounts/services/session";import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";+import { dismissableSessionExpiredDialogAttributes } from "@ente/shared/components/LoginComponents";import VerifyMasterPasswordForm, {type VerifyMasterPasswordFormProps,} from "@ente/shared/components/VerifyMasterPasswordForm";@@ -7,7 +9,7 @@ import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";import type { KeyAttributes, User } from "@ente/shared/user/types";import { t } from "i18next";import { AppContext } from "pages/_app";-import { useContext, useEffect, useState } from "react";+import { useCallback, useContext, useEffect, useState } from "react";interface Iprops {open: boolean;@@ -20,7 +22,8 @@ export default function AuthenticateUserModal({onClose,onAuthenticate,}: Iprops) {- const { setDialogMessage } = useContext(AppContext);+ const { setDialogMessage, setDialogBoxAttributesV2, logout } =+ useContext(AppContext);const [user, setUser] = useState<User>();const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();@@ -31,6 +34,26 @@ export default function AuthenticateUserModal({content: t("UNKNOWN_ERROR"),});+ // This is a altered version of the check we do on the password+ // verification screen, except here it don't try to overwrite local+ // state and instead just request the user to login again if we detect+ // that their password has changed on a different device and they+ // haven't unlocked even once since then on this device.+ const validateSession = useCallback(async () => {+ try {+ const session = await checkSessionValidity();+ if (session.status != "valid") {+ setDialogBoxAttributesV2(+ dismissableSessionExpiredDialogAttributes(logout),+ );+ }+ } catch (e) {+ // Ignore errors since we shouldn't be logging the user out for+ // potentially transient issues.+ log.warn("Ignoring error when determining session validity", e);+ }+ }, [setDialogBoxAttributesV2, logout]);+useEffect(() => {const main = async () => {try {@@ -50,6 +73,7 @@ export default function AuthenticateUserModal({} else {setKeyAttributes(keyAttributes);}+ await validateSession();} catch (e) {log.error("AuthenticateUserModal initialization failed", e);onClose();diff --git a/web/packages/shared/components/LoginComponents.tsx b/web/packages/shared/components/LoginComponents.tsxindex 8201ccacc9..0246189cac 100644--- a/web/packages/shared/components/LoginComponents.tsx+++ b/web/packages/shared/components/LoginComponents.tsx@@ -222,3 +222,21 @@ export const sessionExpiredDialogAttributes = (variant: "accent",},});++/**+ * A variant of {@link sessionExpiredDialogAttributes} that allows the user to+ * close it. This would allow them to, say, view their recovery key if they wish+ * instead of being forced to immediately logout.+ */+export const dismissableSessionExpiredDialogAttributes = (+ onLogin: () => void,+): DialogBoxAttributesV2 => ({+ title: t("SESSION_EXPIRED"),+ content: t("SESSION_EXPIRED_MESSAGE"),+ proceed: {+ text: t("LOGIN"),+ action: onLogin,+ variant: "accent",+ },+ close: { text: t("CANCEL") },+});