mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(licenses): refactor license handling and introduce activation functionality
- Replaced validateLicense with saveLicense in the EnablePaidFeatures component for improved clarity. - Updated user API to include saveLicense and activateLicense methods for better license management. - Enhanced validateLicense function to fetch from a new endpoint and added activateLicense for server activation. - Removed unnecessary console logging in license validation for cleaner code.
This commit is contained in:
@@ -25,7 +25,6 @@ licenseRouter.post(
|
||||
|
||||
try {
|
||||
const result = await validateLicense(licenseKey, serverIp);
|
||||
console.log("Result", result);
|
||||
return c.json(result);
|
||||
} catch (error) {
|
||||
logger.error("Error validating license:", { error });
|
||||
|
||||
@@ -75,6 +75,16 @@ export const validateLicense = async (licenseKey: string, serverIp: string) => {
|
||||
const suscription = await stripe.subscriptions.retrieve(
|
||||
license.stripeSubscriptionId,
|
||||
);
|
||||
const currentServerQuantity = license.serverIps?.length || 0;
|
||||
const serversQuantity = suscription.items.data[0].quantity || 0;
|
||||
|
||||
if (currentServerQuantity >= serversQuantity) {
|
||||
return {
|
||||
isValid: false,
|
||||
error:
|
||||
"You have reached the maximum number of servers, please upgrade your license to add more servers",
|
||||
};
|
||||
}
|
||||
|
||||
if (suscription.status !== "active") {
|
||||
return {
|
||||
@@ -120,6 +130,8 @@ export const activateLicense = async (licenseKey: string, serverIp: string) => {
|
||||
);
|
||||
}
|
||||
|
||||
console.log("License", license.serverIps?.includes(serverIp));
|
||||
|
||||
if (license.serverIps && !license.serverIps.includes(serverIp)) {
|
||||
throw new Error("License is already activated on a different server");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user