Skip to content

Commit 318ad36

Browse files
committed
feat: restrict self-service account deletion to cloud organization owners
1 parent a87a5c0 commit 318ad36

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

‎apps/dokploy/components/dashboard/settings/profile/delete-account.tsx‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ export const DeleteAccount = () => {
4444
const email = data?.user?.email ?? "";
4545
const isBusy = requestCode.isPending || deleteAccount.isPending;
4646

47-
if (
48-
!data ||
49-
hasPassword === undefined ||
50-
(!isCloud && data.role === "owner")
51-
) {
47+
if (!isCloud || !data || data.role !== "owner" || hasPassword === undefined) {
5248
return null;
5349
}
5450

@@ -96,12 +92,10 @@ export const DeleteAccount = () => {
9692
</CardHeader>
9793
<CardContent className="flex flex-col gap-4">
9894
<ul className="text-sm text-muted-foreground list-disc pl-5 space-y-1">
99-
{isCloud && (
100-
<li>
101-
Active subscriptions are cancelled immediately. Invoices already
102-
issued are kept for accounting.
103-
</li>
104-
)}
95+
<li>
96+
Active subscriptions are cancelled immediately. Invoices already
97+
issued are kept for accounting.
98+
</li>
10599
<li>
106100
Every organization you own is deleted, including its projects,
107101
services, environments, domains and server connections.

‎apps/dokploy/server/api/routers/user.ts‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,29 @@ const assertCanDeleteOwnAccount = async (ctx: {
8585
user: { id: string };
8686
session: { impersonatedBy?: string };
8787
}) => {
88+
if (!IS_CLOUD) {
89+
throw new TRPCError({
90+
code: "BAD_REQUEST",
91+
message: "This feature is only available in Dokploy Cloud",
92+
});
93+
}
94+
8895
if (ctx.session.impersonatedBy) {
8996
throw new TRPCError({
9097
code: "FORBIDDEN",
9198
message: "Accounts cannot be deleted while impersonating",
9299
});
93100
}
94101

95-
if (!IS_CLOUD) {
96-
const ownedOrganization = await db.query.organization.findFirst({
97-
where: eq(organization.ownerId, ctx.user.id),
98-
columns: { id: true },
102+
const ownedOrganization = await db.query.organization.findFirst({
103+
where: eq(organization.ownerId, ctx.user.id),
104+
columns: { id: true },
105+
});
106+
if (!ownedOrganization) {
107+
throw new TRPCError({
108+
code: "FORBIDDEN",
109+
message: "Only organization owners can delete their account",
99110
});
100-
if (ownedOrganization) {
101-
throw new TRPCError({
102-
code: "FORBIDDEN",
103-
message:
104-
"Transfer or delete the organizations you own before deleting your account",
105-
});
106-
}
107111
}
108112
};
109113

0 commit comments

Comments
 (0)