Skip to content

armgit / ente

Public Imported from GitHub
0

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

Conv

Manav Rathi5b3f15de343f
diff --git a/web/packages/accounts/pages/two-factor/verify.tsx b/web/packages/accounts/pages/two-factor/verify.tsx
index f7872d2f4a..b961959790 100644
--- a/web/packages/accounts/pages/two-factor/verify.tsx
+++ b/web/packages/accounts/pages/two-factor/verify.tsx
@@ -3,7 +3,7 @@ import type { User } from "ente-accounts/services/user";
import { verifyTwoFactor } from "ente-accounts/services/user";
import { LinkButton } from "ente-base/components/LinkButton";
import { useBaseContext } from "ente-base/context";
-import { HTTPError } from "ente-base/http";
+import { isHTTPErrorWithStatus } from "ente-base/http";
import { getData, setData, setLSUser } from "ente-shared/storage/localStorage";
import { t } from "i18next";
import { useRouter } from "next/router";
@@ -54,7 +54,7 @@ const Page: React.FC = () => {
setData("keyAttributes", keyAttributes);
await router.push(unstashRedirect() ?? "/credentials");
} catch (e) {
- if (e instanceof HTTPError && e.res.status == 404) {
+ if (isHTTPErrorWithStatus(e, 404)) {
logout();
} else {
throw e;
diff --git a/web/packages/accounts/services/recovery-key.ts b/web/packages/accounts/services/recovery-key.ts
index 0f0eb5da97..1d8b29009c 100644
--- a/web/packages/accounts/services/recovery-key.ts
+++ b/web/packages/accounts/services/recovery-key.ts
@@ -7,8 +7,8 @@ import {
toHex,
} from "ente-base/crypto";
import { ensureMasterKeyFromSession } from "ente-base/session";
-import { getData, setData } from "ente-shared/storage/localStorage";
-import { putUserRecoveryKeyAttributes } from "./user";
+import { getData } from "ente-shared/storage/localStorage";
+import { putUserRecoveryKeyAttributes, saveKeyAttributes } from "./user";
// Mobile client library only supports English.
bip39.setDefaultWordlist("english");
@@ -115,10 +115,7 @@ const createNewRecoveryKey = async (masterKey: string) => {
await putUserRecoveryKeyAttributes(recoveryKeyAttributes);
- setData("keyAttributes", {
- ...existingAttributes,
- ...recoveryKeyAttributes,
- });
+ saveKeyAttributes({ ...existingAttributes, ...recoveryKeyAttributes });
return recoveryKey;
};
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts
index fc92de362b..938a86b9b3 100644
--- a/web/packages/accounts/services/user.ts
+++ b/web/packages/accounts/services/user.ts
@@ -5,7 +5,7 @@ import {
publicRequestHeaders,
} from "ente-base/http";
import { apiURL } from "ente-base/origins";
-import { getData, setData, setLSUser } from "ente-shared/storage/localStorage";
+import { getData, setLSUser } from "ente-shared/storage/localStorage";
import { nullToUndefined } from "ente-utils/transform";
import { z } from "zod/v4";
import { getUserRecoveryKey, recoveryKeyFromMnemonic } from "./recovery-key";
@@ -279,6 +279,14 @@ export const savedKeyAttributes = (): KeyAttributes | undefined => {
export const ensureSavedKeyAttributes = (): KeyAttributes =>
ensureExpectedLoggedInValue(savedKeyAttributes());
+/**
+ * Save the user's {@link KeyAttributes} in local storage.
+ *
+ * Use {@link savedKeyAttributes} to retrieve them.
+ */
+export const saveKeyAttributes = (keyAttributes: KeyAttributes) =>
+ localStorage.setItem("keyAttributes", JSON.stringify(keyAttributes));
+
/**
* Update or set the user's {@link KeyAttributes} on remote.
*/
@@ -704,7 +712,7 @@ export const recoverTwoFactorFinish = async (
encryptedToken,
token: undefined,
});
- setData("keyAttributes", keyAttributes);
+ saveKeyAttributes(keyAttributes);
};
const removeTwoFactor = async (