del api
This commit is contained in:
@@ -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 & {
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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 }),
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user