π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Conv
Manav Rathi093e3a006113
diff --git a/web/packages/accounts/components/SignUpContents.tsx b/web/packages/accounts/components/SignUpContents.tsxindex d87b5fa4e3..343683c846 100644--- a/web/packages/accounts/components/SignUpContents.tsx+++ b/web/packages/accounts/components/SignUpContents.tsx@@ -16,7 +16,7 @@ import {import {saveJustSignedUp,setData,- setLocalReferralSource,+ stashReferralSource,} from "ente-accounts/services/accounts-db";import {generateSRPSetupAttributes,@@ -107,7 +107,8 @@ export const SignUpContents: React.FC<SignUpContentsProps> = ({}try {- setLocalReferralSource(referral);+ const cleanedReferral = referral.trim();+ if (cleanedReferral) stashReferralSource(cleanedReferral);try {await sendOTT(email, "signup");diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsxindex a14f005ab1..a2aa9816fd 100644--- a/web/packages/accounts/pages/verify.tsx+++ b/web/packages/accounts/pages/verify.tsx@@ -9,10 +9,10 @@ import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice"import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/second-factor-choice";import {getData,- getLocalReferralSource,saveIsFirstLogin,setData,setLSUser,+ unstashReferralSource,} from "ente-accounts/services/accounts-db";import {openPasskeyVerificationURL,@@ -83,8 +83,7 @@ const Page: React.FC = () => {setFieldError,) => {try {- // eslint-disable-next-line @typescript-eslint/no-unsafe-call- const referralSource = getLocalReferralSource()?.trim();+ const referralSource = unstashReferralSource();const cleanedReferral = referralSource? `web:${referralSource}`: undefined;diff --git a/web/packages/accounts/services/accounts-db.ts b/web/packages/accounts/services/accounts-db.tsindex 553f3c8f44..26a3275808 100644--- a/web/packages/accounts/services/accounts-db.ts+++ b/web/packages/accounts/services/accounts-db.ts@@ -3,18 +3,16 @@ import log from "ente-base/log";import { nullToUndefined } from "ente-utils/transform";import { z } from "zod/v4";import { RemoteKeyAttributes, type KeyAttributes } from "./user";+export type LocalStorageKey =| "user"// See also savedKeyAttributes.| "keyAttributes"| "originalKeyAttributes"- | "isFirstLogin"- | "justSignedUp"| "showBackButton"// Moved to ente-accounts// "srpSetupAttributes"- | "srpAttributes"- | "referralSource";+ | "srpAttributes";/*** [Note: Accounts DB]@@ -252,10 +250,45 @@ export const getAndClearJustSignedUp = () => {return result;};-export function getLocalReferralSource() {- return getData("referralSource")?.source;-}+/**+ * Zod schema for the format in which the {@link stashReferralSource} used to+ * saved the referral source in local storage.+ *+ * Starting 1.7.15-beta (July 2025), we started saving the string directly, but+ * when reading we fallback to the old format if needed. This fallback can be+ * removed, and soonish, since these is a transient value that isn't expected to+ * remain in the user's local storage for long anyway. (tag: Migration).+ */+const LocalLegacyReferralSource = z.object({ source: z.string() });++/**+ * Save the referral source entered by the user on the signup screen in local+ * storage.+ *+ * The saved value can be retrieved post email verification using+ * {@link unstashReferralSource}.+ */+export const stashReferralSource = (referralSource: string) => {+ localStorage.setItem("referralSource", referralSource);+};-export function setLocalReferralSource(source: string) {- setData("referralSource", { source });-}+/**+ * Retrieve the previously saved referral source (using+ * {@link stashReferralSource}), returning the saved value and also clearing it+ * from local storage.+ */+export const unstashReferralSource = () => {+ const jsonString = localStorage.getItem("referralSource");+ if (!jsonString) return undefined;+ localStorage.removeItem("referralSource");+ try {+ // Try the old format first. The trim is also a legacy expectation and+ // can be removed when we remove this fallfront.+ return LocalLegacyReferralSource.parse(+ JSON.parse(jsonString),+ ).source.trim();+ } catch {+ // Otherwise try the new format.+ return jsonString;+ }+};