diff --git a/src/ui/pages/DeleteAccount.tsx b/src/ui/pages/DeleteAccount.tsx index 1663f8e..305f891 100644 --- a/src/ui/pages/DeleteAccount.tsx +++ b/src/ui/pages/DeleteAccount.tsx @@ -1,7 +1,50 @@ +import { expectedOrigin, newCall } from "@app/index"; +import { useState } from "react"; + function DeleteAccount() { + const url = `${expectedOrigin()}/account/delete`; + + const [status, setStatus] = useState(null); + return ( -
+
+ To delete your account, click the button below. + { status && ( + {status} + ) } + { + // Check if the credentials are stored. + const creds = localStorage.getItem("credentials"); + if (!creds) { + window.open(`${expectedOrigin()}/login?redirect=${url}&app=Delete Account&handoff=true`); + setStatus("Follow the link to delete your account."); + } else try { + // Parse the credentials. + const { token } = JSON.parse(creds); + // Attempt to delete the account. + const response = await fetch(newCall("account"), { + method: "DELETE", + headers: { Authorization: token } + }); + + if (response.status == 200) { + setStatus("Account deleted successfully."); + // Remove the credentials. + localStorage.removeItem("credentials"); + } else { + setStatus("Unable to delete account Please contact us at support@seikimo.moe."); + } + } catch (error) { + window.open(`${expectedOrigin()}/login?redirect=${url}&app=Delete Account&handoff=true`); + setStatus("Follow the link to delete your account."); + } + }} + > + Delete Account +
); }