diff --git a/app/routes/account/delete.tsx b/app/routes/account/delete.tsx
new file mode 100644
index 0000000..cef7ab5
--- /dev/null
+++ b/app/routes/account/delete.tsx
@@ -0,0 +1,11 @@
+import type { ActionFunction, LoaderFunction } from "remix";
+import { redirect } from "remix";
+import { deleteUser } from "~/utils/session.server";
+
+export const action: ActionFunction = async ({ request }) => {
+ return deleteUser(request);
+};
+
+export const loader: LoaderFunction = async () => {
+ return redirect("/");
+};
diff --git a/app/routes/account/manage.tsx b/app/routes/account/manage.tsx
index 91f3f0d..6b615ab 100644
--- a/app/routes/account/manage.tsx
+++ b/app/routes/account/manage.tsx
@@ -353,6 +353,34 @@ export default function AccountPreferencesRoute() {
+
+
+
+
+
+
+
+
+ Do you really want to delete your account? All your data will be
+ permanently deleted.
+
+
+
+
+
+
+
>
);
}
diff --git a/app/utils/session.server.ts b/app/utils/session.server.ts
index 5ad5ae4..9bcc7d1 100644
--- a/app/utils/session.server.ts
+++ b/app/utils/session.server.ts
@@ -68,6 +68,21 @@ export async function updateUser({ id, ...data }: UpdateUserForm) {
return user;
}
+export async function deleteUser(request: Request) {
+ const userId = await getUserId(request);
+ if (!userId) return null;
+
+ const deletedUser = await db.user.delete({ where: { id: userId } });
+ if (!deletedUser) return null;
+
+ const session = await storage.getSession(request.headers.get("Cookie"));
+ return redirect("/", {
+ headers: {
+ "Set-Cookie": await storage.destroySession(session),
+ },
+ });
+}
+
export async function login({ username, password }: LoginForm) {
const user = await db.user.findUnique({
where: { username },