49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import type { GetServerSidePropsContext } from "next";
|
|
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
import { getDeploymentKey } from "@calcom/features/ee/deployment/lib/getDeploymentKey";
|
|
import { DeploymentRepository } from "@calcom/lib/server/repository/deployment";
|
|
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(),
|
|
},
|
|
});
|
|
}
|
|
|
|
const isFreeLicense = (await getDeploymentKey(deploymentRepo)) === "";
|
|
|
|
return {
|
|
props: {
|
|
isFreeLicense,
|
|
userCount,
|
|
},
|
|
};
|
|
}
|