New Rules stay off lists until the person who holds the pen turns on a share link, or the team features one. Uploaded files are readable only by those readers, stripped of location metadata, and deleted with the Rule, draft, or account.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { prisma } from "../../../../lib/server/db";
|
|
import { isDatabaseConfigured } from "../../../../lib/server/env";
|
|
import {
|
|
dbUnavailable,
|
|
internalError,
|
|
unauthorized,
|
|
} from "../../../../lib/server/responses";
|
|
import {
|
|
clearSessionCookie,
|
|
getSessionUser,
|
|
} from "../../../../lib/server/session";
|
|
import { apiRoute } from "../../../../lib/server/apiRoute";
|
|
import { deleteUploadsForUser } from "../../../../lib/server/uploads/deleteUploadedFiles";
|
|
|
|
/**
|
|
* Delete the signed-in user and associated data.
|
|
*
|
|
* Prisma `User` deletion cascades `Session`, `RuleDraft`, and `PublishedRule`
|
|
* (and uploads linked to those rows). Disk files are removed first.
|
|
*/
|
|
export const DELETE = apiRoute("user.me.delete", async () => {
|
|
if (!isDatabaseConfigured()) {
|
|
return dbUnavailable();
|
|
}
|
|
|
|
const user = await getSessionUser();
|
|
if (!user) {
|
|
return unauthorized();
|
|
}
|
|
|
|
try {
|
|
await deleteUploadsForUser(user.id);
|
|
await prisma.user.delete({ where: { id: user.id } });
|
|
} catch {
|
|
return internalError("Failed to delete account");
|
|
}
|
|
|
|
await clearSessionCookie();
|
|
|
|
return NextResponse.json({ ok: true });
|
|
});
|