This commit is contained in:
Manav Rathi
2025-02-26 18:46:38 +05:30
parent 818fba9435
commit cba85799f0
3 changed files with 24 additions and 27 deletions

View File

@@ -7,7 +7,10 @@ import {
DropdownInput,
type DropdownOption,
} from "@/new/photos/components/DropdownInput";
import { getAccountDeleteChallenge } from "@/new/photos/services/user";
import {
deleteAccount,
getAccountDeleteChallenge,
} from "@/new/photos/services/user";
import { initiateEmail } from "@/new/photos/utils/web";
import { decryptDeleteAccountChallenge } from "@ente/shared/crypto/helpers";
import {
@@ -23,7 +26,6 @@ import { useFormik } from "formik";
import { t } from "i18next";
import React, { useState } from "react";
import { Trans } from "react-i18next";
import { deleteAccount } from "services/userService";
type DeleteAccountProps = ModalVisibilityProps & {
/**

View File

@@ -80,28 +80,3 @@ export const getUserDetailsV2 = async (): Promise<UserDetails> => {
throw e;
}
};
export const deleteAccount = async (
challenge: string,
reason: string,
feedback: string,
) => {
try {
const token = getToken();
if (!token) {
return;
}
await HTTPService.delete(
await apiURL("/users/delete"),
{ challenge, reason, feedback },
null,
{
"X-Auth-Token": token,
},
);
} catch (e) {
log.error("deleteAccount api call failed", e);
throw e;
}
};

View File

@@ -41,3 +41,23 @@ export const getAccountDeleteChallenge = async () => {
ensureOk(res);
return DeleteChallengeResponse.parse(await res.json());
};
/**
* Delete the logged in user's account on remote.
*
* @param challenge Decrypted value of the challenge previously obtained via
* {@link getAccountDeleteChallenge}. The decryption algorithm is implemented in
* {@link decryptDeleteAccountChallenge}.
*/
export const deleteAccount = async (
challenge: string,
reason: string,
feedback: string,
) =>
ensureOk(
await fetch(await apiURL("/users/delete"), {
method: "DELETE",
headers: await authenticatedRequestHeaders(),
body: JSON.stringify({ challenge, reason, feedback }),
}),
);