-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(account): Add page to delete your account
i deleted my production account to test this.
- Loading branch information
1 parent
ea2e077
commit 5e9f043
Showing
1 changed file
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
|