Files
calendar/apps/web/server/lib/setup/getServerSideProps.tsx
T
Benny JooandGitHub cb7844fd22 refactor: Migrate repositories/services from /lib to /features (#25925)
* deployment

* update imports

* booking report

* update import paths

* watch list

* watch list

* api key

* api key

* selected slots

* wip

* event type translation

* work flow step

* booking reference

* fix tests

* fix

* fix

* migrate

* wip

* address

* fix
2025-12-17 14:14:50 +00:00

55 lines
1.8 KiB
TypeScript

import type { GetServerSidePropsContext } from "next";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { LicenseKeySingleton } from "@calcom/features/ee/common/server/LicenseKeyService";
import { getDeploymentKey } from "@calcom/features/ee/deployment/lib/getDeploymentKey";
import { DeploymentRepository } from "@calcom/features/ee/deployment/repositories/DeploymentRepository";
import prisma from "@calcom/prisma";
import { UserPermissionRole } from "@calcom/prisma/enums";
export async function getServerSideProps(context: GetServerSidePropsContext) {
const { req } = context;
const userCount = await prisma.user.count();
const session = await getServerSession({ req });
if (session?.user.role && session?.user.role !== UserPermissionRole.ADMIN) {
return {
notFound: true,
} as const;
}
// direct access is intentional.
const deploymentRepo = new DeploymentRepository(prisma);
const licenseKey = await deploymentRepo.getLicenseKeyWithId(1);
// Check existent CALCOM_LICENSE_KEY env var and account for it
if (!!process.env.CALCOM_LICENSE_KEY && !licenseKey) {
await prisma.deployment.upsert({
where: { id: 1 },
update: {
licenseKey: process.env.CALCOM_LICENSE_KEY,
agreedLicenseAt: new Date(),
},
create: {
licenseKey: process.env.CALCOM_LICENSE_KEY,
agreedLicenseAt: new Date(),
},
});
}
// Check if there's already a valid license using LicenseKeyService
const licenseKeyService = await LicenseKeySingleton.getInstance(deploymentRepo);
const hasValidLicense = await licenseKeyService.checkLicense();
const isFreeLicense = (await getDeploymentKey(deploymentRepo)) === "";
return {
props: {
isFreeLicense,
userCount,
hasValidLicense,
},
};
}