Skip to content

Commit

Permalink
feat(account): Add page to delete your account
Browse files Browse the repository at this point in the history
i deleted my production account to test this.
  • Loading branch information
KingRainbow44 committed Apr 7, 2024
1 parent ea2e077 commit 5e9f043
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/ui/pages/DeleteAccount.tsx
Original file line number Diff line number Diff line change
@@ -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<string | null>(null);

return (
<div className={"DeleteAccount"}>
<div className={"flex flex-col p-5"}>
<span>To delete your account, click the button below.</span>
{ status && (
<span>{status}</span>
) }
<span
className={"px-2 py-1 bg-blue-500 w-fit hover:cursor-pointer"}
onClick={async () => {
// 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 [email protected].");
}
} catch (error) {
window.open(`${expectedOrigin()}/login?redirect=${url}&app=Delete Account&handoff=true`);
setStatus("Follow the link to delete your account.");
}
}}
>
Delete Account
</span>
</div>
);
}
Expand Down

0 comments on commit 5e9f043

Please sign in to comment.