Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update

Manav Rathi70b5b8e682c5
diff --git a/web/packages/accounts/components/LoginContents.tsx b/web/packages/accounts/components/LoginContents.tsx
index a741a235b5..f3107993f5 100644
--- a/web/packages/accounts/components/LoginContents.tsx
+++ b/web/packages/accounts/components/LoginContents.tsx
@@ -1,7 +1,7 @@
import { Input, Stack, TextField, Typography } from "@mui/material";
import { AccountsPageFooter } from "ente-accounts/components/layouts/centered-paper";
import {
- savePartialLocalUser,
+ replaceSavedLocalUser,
saveSRPAttributes,
} from "ente-accounts/services/accounts-db";
import { getSRPAttributes } from "ente-accounts/services/srp";
@@ -51,10 +51,10 @@ export const LoginContents: React.FC<LoginContentsProps> = ({
}
throw e;
}
- savePartialLocalUser({ email });
+ replaceSavedLocalUser({ email });
void router.push("/verify");
} else {
- savePartialLocalUser({ email });
+ replaceSavedLocalUser({ email });
saveSRPAttributes(srpAttributes);
void router.push("/credentials");
}
diff --git a/web/packages/accounts/components/SignUpContents.tsx b/web/packages/accounts/components/SignUpContents.tsx
index bf82767f64..b4c3372f06 100644
--- a/web/packages/accounts/components/SignUpContents.tsx
+++ b/web/packages/accounts/components/SignUpContents.tsx
@@ -14,9 +14,9 @@ import {
Typography,
} from "@mui/material";
import {
+ replaceSavedLocalUser,
saveJustSignedUp,
saveOriginalKeyAttributes,
- savePartialLocalUser,
stashReferralSource,
stashSRPSetupAttributes,
} from "ente-accounts/services/accounts-db";
@@ -130,7 +130,7 @@ export const SignUpContents: React.FC<SignUpContentsProps> = ({
throw e;
}
- savePartialLocalUser({ email });
+ replaceSavedLocalUser({ email });
let gkResult: GenerateKeysAndAttributesResult;
try {
diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx
index 12c6cfa773..3817b4d1fa 100644
--- a/web/packages/accounts/pages/verify.tsx
+++ b/web/packages/accounts/pages/verify.tsx
@@ -8,6 +8,7 @@ import { VerifyingPasskey } from "ente-accounts/components/LoginComponents";
import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice";
import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/second-factor-choice";
import {
+ replaceSavedLocalUser,
savedKeyAttributes,
savedOriginalKeyAttributes,
savedPartialLocalUser,
@@ -15,7 +16,6 @@ import {
saveIsFirstLogin,
saveKeyAttributes,
saveOriginalKeyAttributes,
- setLSUser,
unstashAfterUseSRPSetupAttributes,
unstashReferralSource,
updateSavedLocalUser,
@@ -44,6 +44,7 @@ import { useBaseContext } from "ente-base/context";
import { isHTTPErrorWithStatus } from "ente-base/http";
import log from "ente-base/log";
import { clearSessionStorage } from "ente-base/session";
+import { saveAuthToken } from "ente-base/token";
import { t } from "i18next";
import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react";
@@ -103,6 +104,9 @@ const Page: React.FC = () => {
await verifyEmail(email, ott, cleanedReferral),
);
+ // The following flow is similar to (but not the same) as what
+ // happens after `verifySRP` in the `/credentials` page.
+
if (passkeySessionID) {
updateSavedLocalUser({ passkeySessionID });
saveIsFirstLogin();
@@ -120,15 +124,8 @@ const Page: React.FC = () => {
saveIsFirstLogin();
void router.push("/two-factor/verify");
} else {
- await setLSUser({
- email,
- token,
- encryptedToken,
- id,
- isTwoFactorEnabled: undefined,
- twoFactorSessionID: undefined,
- passkeySessionID: undefined,
- });
+ if (token) await saveAuthToken(token);
+ replaceSavedLocalUser({ id, email, token, encryptedToken });
if (keyAttributes) {
saveKeyAttributes(keyAttributes);
saveOriginalKeyAttributes(keyAttributes);
diff --git a/web/packages/accounts/services/accounts-db.ts b/web/packages/accounts/services/accounts-db.ts
index 18f4259922..eda8fe69e8 100644
--- a/web/packages/accounts/services/accounts-db.ts
+++ b/web/packages/accounts/services/accounts-db.ts
@@ -118,7 +118,7 @@ const LocalUser = z.object({
* After the user is logged in, use {@link savedLocalUser} or
* {@link ensureLocalUser} instead.
*
- * Use {@link savePartialLocalUser} to updated the saved value.
+ * Use {@link replaceSavedLocalUser} to updated the saved value.
*/
export const savedPartialLocalUser = (): PartialLocalUser | undefined => {
const jsonString = localStorage.getItem("user");
@@ -131,32 +131,32 @@ export const savedPartialLocalUser = (): PartialLocalUser | undefined => {
*
* See: [Note: Partial local user].
*
- * This method replaces the existing data. Use {@link updatePartialLocalUser} to
+ * This method replaces the existing data. Use {@link updateSavedLocalUser} to
* update selected fields while keeping the other fields as it is.
*
* TODO: WARNING: This does not update the KV token. The idea is to gradually
* move over uses of setLSUser to this while explicitly setting the KV token
* where needed.
*/
-export const savePartialLocalUser = (partialLocalUser: PartialLocalUser) =>
+export const replaceSavedLocalUser = (partialLocalUser: PartialLocalUser) =>
localStorage.setItem("user", JSON.stringify(partialLocalUser));
/**
* Partially update the saved user data.
*
- * This is a delta variant of {@link savePartialLocalUser}, which replaces the
+ * This is a delta variant of {@link replaceSavedLocalUser}, which replaces the
* entire saved object, while this function spreads the provided {@link updates}
* onto the currently saved value.
*
* @param updates A subset of {@link PartialLocalUser} fields that we'd like to
- * update. The other fields, if any, remain unchanged.
+ * update. The other fields, if present in local storage, remain unchanged.
*
* TODO: WARNING: This does not update the KV token. The idea is to gradually
* move over uses of setLSUser to this while explicitly setting the KV token
* where needed.
*/
export const updateSavedLocalUser = (updates: Partial<PartialLocalUser>) =>
- savePartialLocalUser({ ...savedPartialLocalUser(), ...updates });
+ replaceSavedLocalUser({ ...savedPartialLocalUser(), ...updates });
/**
* Return data about the logged-in user, if someone is indeed logged in.
@@ -167,7 +167,7 @@ export const updateSavedLocalUser = (updates: Partial<PartialLocalUser>) =>
* not accessible to web workers.
*
* There is no setter corresponding to this function since this is only a view
- * on data saved using {@link savePartialLocalUser} or
+ * on data saved using {@link replaceSavedLocalUser} or
* {@link updateSavedLocalUser}.
*
* See: [Note: Partial local user] for more about the whole shebang.