From 3c03bbac0576f814f83cbcba3e27a93be6147bac Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 7 Nov 2024 09:30:54 +0530 Subject: [PATCH] copy over --- web/packages/new/photos/services/user.ts | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.ts index 622c7f37eb..f3284fca78 100644 --- a/web/packages/new/photos/services/user.ts +++ b/web/packages/new/photos/services/user.ts @@ -1,6 +1,7 @@ import { authenticatedRequestHeaders, ensureOk } from "@/base/http"; import { getKV, setKV } from "@/base/kv"; import { apiURL } from "@/base/origins"; +import { getData, LS_KEYS, setLSUser } from "@ente/shared/storage/localStorage"; import { z } from "zod"; import { FamilyData } from "./family"; import { Subscription } from "./plan"; @@ -116,6 +117,32 @@ export const syncUserDetails = async () => { const userDetails = await getUserDetailsV2(); await setKV("userDetails", userDetails); setUserDetailsSnapshot(userDetails); + + // TODO: The existing code used to also set the email for the local storage + // user whenever it updated the user details. I don't see why this would be + // needed though. + // + // Retaining the existing behaviour for now, except we throw. The intent is + // to remove this entire copy-over after a bit. + // + // Added Nov 2024, and can be removed after a while (tag: Migration). + + const oldLSUser = getData(LS_KEYS.USER) as unknown; + const hasMatchingEmail = + oldLSUser && + typeof oldLSUser == "object" && + "email" in oldLSUser && + typeof oldLSUser.email == "string" && + oldLSUser.email == userDetails.email; + + if (!hasMatchingEmail) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + await setLSUser({ + ...getData(LS_KEYS.USER), + email: userDetails.email, + }); + throw new Error("EmailĀ in local storage did not match user details"); + } }; /**