mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: add license
This commit is contained in:
@@ -54,9 +54,9 @@ const tabMap: Record<TabState, TabInfo> = {
|
|||||||
label: "Requests",
|
label: "Requests",
|
||||||
description: "Manage your requests",
|
description: "Manage your requests",
|
||||||
index: "/dashboard/requests",
|
index: "/dashboard/requests",
|
||||||
// isShow: ({ rol, user }) => {
|
isShow: ({ rol, user }) => {
|
||||||
// return Boolean(rol === "admin" || user?.canAccessToDocker);
|
return Boolean(rol === "admin" || user?.canAccessToDocker);
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
label: "Settings",
|
label: "Settings",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type { GetServerSidePropsContext } from "next";
|
|||||||
import type { ReactElement } from "react";
|
import type { ReactElement } from "react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ShowRequests } from "@/components/dashboard/requests/show-requests";
|
import { ShowRequests } from "@/components/dashboard/requests/show-requests";
|
||||||
|
import { isValidLicense } from "@/server/api/services/license";
|
||||||
|
|
||||||
export default function Requests() {
|
export default function Requests() {
|
||||||
return <ShowRequests />;
|
return <ShowRequests />;
|
||||||
@@ -24,6 +25,17 @@ export async function getServerSideProps(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isValid = await isValidLicense();
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: true,
|
||||||
|
destination: "/dashboard/projects",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {},
|
props: {},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ import { toast } from "sonner";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
licenseKey: z.string().min(1, {
|
licenseKey: z.string(),
|
||||||
message: "License key is required",
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
type Schema = z.infer<typeof schema>;
|
type Schema = z.infer<typeof schema>;
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ export const licenseRouter = createTRPCRouter({
|
|||||||
setLicense: adminProcedure.input(z.string()).mutation(async ({ input }) => {
|
setLicense: adminProcedure.input(z.string()).mutation(async ({ input }) => {
|
||||||
const admin = await findAdmin();
|
const admin = await findAdmin();
|
||||||
|
|
||||||
|
if (!input) {
|
||||||
|
return await updateAdmin(admin.authId, {
|
||||||
|
licenseKey: "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await fetch("http://127.0.0.1:4000/v1/validate-license", {
|
const result = await fetch("http://127.0.0.1:4000/v1/validate-license", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
18
apps/dokploy/server/api/services/license.ts
Normal file
18
apps/dokploy/server/api/services/license.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { findAdmin } from "./admin";
|
||||||
|
|
||||||
|
export const isValidLicense = async () => {
|
||||||
|
const admin = await findAdmin();
|
||||||
|
|
||||||
|
const result = await fetch("http://127.0.0.1:4000/v1/validate-license", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
licenseKey: admin.licenseKey,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await result.json();
|
||||||
|
return data.valid;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user