Skip to content

Scheduling infrastructure for absolutely everyone.

feat: adds license check

Agusti Fernandez Pardo12fe6af995a6
diff --git a/.env.example b/.env.example
index eec3f283f75..c5354bfd7da 100644
--- a/.env.example
+++ b/.env.example
@@ -1,3 +1,6 @@
API_KEY_PREFIX=cal_
DATABASE_URL="postgresql://postgres:@localhost:5450/calendso"
-NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
\ No newline at end of file
+NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
+
+# Get it in console.cal.com
+CALCOM_LICENSE_KEY=""
diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts
index b915df66261..408cc553561 100644
--- a/lib/helpers/verifyApiKey.ts
+++ b/lib/helpers/verifyApiKey.ts
@@ -1,6 +1,7 @@
import { NextMiddleware } from "next-api-middleware";
import { hashAPIKey } from "@calcom/features/ee/api-keys/lib/apiKeys";
+import checkLicense from "@calcom/features/ee/common/server/checkLicense";
import { isAdminGuard } from "@lib/utils/isAdmin";
@@ -14,6 +15,9 @@ export const dateNotInPast = function (date: Date) {
// This verifies the apiKey and sets the user if it is valid.
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
+ const hasValidLicense = await checkLicense(process.env.CALCOM_LICENSE_KEY || "");
+ if (!hasValidLicense)
+ return res.status(401).json({ error: "Invalid or missing CALCOM_LICENSE_KEY environment variable" });
const { prisma, userId, isAdmin } = req;
// If the user is an admin and using a license key (from customPrisma), skip the apiKey check.
if (userId === 0 && isAdmin) {