Add enterprise features management: implement license key settings and update user schema

This commit is contained in:
Mauricio Siu
2026-01-28 22:34:17 -06:00
parent f680818b56
commit 25fa362cdb
4 changed files with 163 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ import { mountRouter } from "./routers/mount";
import { mysqlRouter } from "./routers/mysql";
import { notificationRouter } from "./routers/notification";
import { organizationRouter } from "./routers/organization";
import { licenseKeyRouter } from "./routers/proprietary/license-key";
import { portRouter } from "./routers/port";
import { postgresRouter } from "./routers/postgres";
import { previewDeploymentRouter } from "./routers/preview-deployment";
@@ -82,6 +83,7 @@ export const appRouter = createTRPCRouter({
swarm: swarmRouter,
ai: aiRouter,
organization: organizationRouter,
licenseKey: licenseKeyRouter,
schedule: scheduleRouter,
rollback: rollbackRouter,
volumeBackups: volumeBackupsRouter,

View File

@@ -0,0 +1,52 @@
import { user } from "@dokploy/server/db/schema";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
import { z } from "zod";
import { adminProcedure, createTRPCRouter } from "@/server/api/trpc";
import { db } from "@/server/db";
export const licenseKeyRouter = createTRPCRouter({
getEnterpriseSettings: adminProcedure.query(async ({ ctx }) => {
const currentUserId = ctx.user.id;
const currentUser = await db.query.user.findFirst({
where: eq(user.id, currentUserId),
});
if (!currentUser) {
throw new TRPCError({
code: "NOT_FOUND",
message: "User not found",
});
}
return {
enableEnterpriseFeatures: !!currentUser.enableEnterpriseFeatures,
licenseKey: currentUser.licenseKey ?? "",
};
}),
updateEnterpriseSettings: adminProcedure
.input(
z.object({
enableEnterpriseFeatures: z.boolean().optional(),
licenseKey: z.string().optional(),
}),
)
.mutation(async ({ ctx, input }) => {
const currentUserId = ctx.user.id;
await db
.update(user)
.set({
...(input.enableEnterpriseFeatures === undefined
? {}
: { enableEnterpriseFeatures: input.enableEnterpriseFeatures }),
...(input.licenseKey === undefined
? {}
: { licenseKey: input.licenseKey }),
})
.where(eq(user.id, currentUserId));
return true;
}),
});