From 5e9f043a455f8cd1a45f4456a9e659eeae9a1888 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sun, 7 Apr 2024 18:14:31 -0400 Subject: [PATCH] feat(account): Add page to delete your account i deleted my production account to test this. --- src/ui/pages/DeleteAccount.tsx | 45 +++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) 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 +
); }