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:
Mauricio Siu
2025-03-23 19:04:24 -06:00
parent 5fd8fcfa1e
commit 4074942dbf
5 changed files with 36 additions and 8 deletions

View File

@@ -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 });

View File

@@ -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");
}