Skip to content

armgit / ente

Public Imported from GitHub
0

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

Conv

Manav Rathi16246d8d583f
diff --git a/web/packages/accounts/pages/two-factor/setup.tsx b/web/packages/accounts/pages/two-factor/setup.tsx
index 448f4e74ff..36d7d27d8a 100644
--- a/web/packages/accounts/pages/two-factor/setup.tsx
+++ b/web/packages/accounts/pages/two-factor/setup.tsx
@@ -31,7 +31,13 @@ const Page: React.FC = () => {
const recoveryEncryptedTwoFactorSecret = await encryptWithRecoveryKey(
twoFactorSecret!.secretCode,
);
- await enableTwoFactor(otp, recoveryEncryptedTwoFactorSecret);
+ await enableTwoFactor({
+ code: otp,
+ encryptedTwoFactorSecret:
+ recoveryEncryptedTwoFactorSecret.encryptedData,
+ twoFactorSecretDecryptionNonce:
+ recoveryEncryptedTwoFactorSecret.nonce,
+ });
await setLSUser({
...getData(LS_KEYS.USER),
isTwoFactorEnabled: true,
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts
index 0138ca359c..b1992c890a 100644
--- a/web/packages/accounts/services/user.ts
+++ b/web/packages/accounts/services/user.ts
@@ -1,4 +1,3 @@
-import type { B64EncryptionResult } from "@/base/crypto/libsodium";
import {
authenticatedRequestHeaders,
ensureOk,
@@ -307,25 +306,24 @@ export const setupTwoFactor = async () => {
return TwoFactorSecret.parse(await res.json());
};
-export const enableTwoFactor = async (
- code: string,
- recoveryEncryptedTwoFactorSecret: B64EncryptionResult,
-) => {
- await HTTPService.post(
- await apiURL("/users/two-factor/enable"),
- {
- code,
- encryptedTwoFactorSecret:
- recoveryEncryptedTwoFactorSecret.encryptedData,
- twoFactorSecretDecryptionNonce:
- recoveryEncryptedTwoFactorSecret.nonce,
- },
- undefined,
- {
- "X-Auth-Token": getToken(),
- },
+interface EnableTwoFactorRequest {
+ code: string;
+ encryptedTwoFactorSecret: string;
+ twoFactorSecretDecryptionNonce: string;
+}
+
+/**
+ * Enable two factor for the user by providing the 2FA code and the encrypted
+ * secret from a previous call to {@link setupTwoFactor}.
+ */
+export const enableTwoFactor = async (req: EnableTwoFactorRequest) =>
+ ensureOk(
+ await fetch(await apiURL("/users/two-factor/enable"), {
+ method: "POST",
+ headers: await authenticatedRequestHeaders(),
+ body: JSON.stringify(req),
+ }),
);
-};
export const setRecoveryKey = async (token: string, recoveryKey: RecoveryKey) =>
HTTPService.put(