feat: restrict self-service account deletion to cloud organization owners

This commit is contained in:
Mauricio Siu
2026-09-14 11:05:26 -06:00
parent a87a5c06f0
commit 318ad36967
2 changed files with 20 additions and 22 deletions
@@ -44,11 +44,7 @@ export const DeleteAccount = () => {
const email = data?.user?.email ?? "";
const isBusy = requestCode.isPending || deleteAccount.isPending;
if (
!data ||
hasPassword === undefined ||
(!isCloud && data.role === "owner")
) {
if (!isCloud || !data || data.role !== "owner" || hasPassword === undefined) {
return null;
}
@@ -96,12 +92,10 @@ export const DeleteAccount = () => {
</CardHeader>
<CardContent className="flex flex-col gap-4">
<ul className="text-sm text-muted-foreground list-disc pl-5 space-y-1">
{isCloud && (
<li>
Active subscriptions are cancelled immediately. Invoices already
issued are kept for accounting.
</li>
)}
<li>
Active subscriptions are cancelled immediately. Invoices already
issued are kept for accounting.
</li>
<li>
Every organization you own is deleted, including its projects,
services, environments, domains and server connections.
+15 -11
View File
@@ -85,6 +85,13 @@ const assertCanDeleteOwnAccount = async (ctx: {
user: { id: string };
session: { impersonatedBy?: string };
}) => {
if (!IS_CLOUD) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "This feature is only available in Dokploy Cloud",
});
}
if (ctx.session.impersonatedBy) {
throw new TRPCError({
code: "FORBIDDEN",
@@ -92,18 +99,15 @@ const assertCanDeleteOwnAccount = async (ctx: {
});
}
if (!IS_CLOUD) {
const ownedOrganization = await db.query.organization.findFirst({
where: eq(organization.ownerId, ctx.user.id),
columns: { id: true },
const ownedOrganization = await db.query.organization.findFirst({
where: eq(organization.ownerId, ctx.user.id),
columns: { id: true },
});
if (!ownedOrganization) {
throw new TRPCError({
code: "FORBIDDEN",
message: "Only organization owners can delete their account",
});
if (ownedOrganization) {
throw new TRPCError({
code: "FORBIDDEN",
message:
"Transfer or delete the organizations you own before deleting your account",
});
}
}
};