mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
25 lines
804 B
TypeScript
25 lines
804 B
TypeScript
import { cookies, headers } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
|
import { prisma } from "@calcom/prisma";
|
|
|
|
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
|
|
|
export async function checkInsightsPagePermission() {
|
|
const featuresRepository = new FeaturesRepository(prisma);
|
|
const insightsEnabled = await featuresRepository.checkIfFeatureIsEnabledGlobally("insights");
|
|
|
|
if (!insightsEnabled) {
|
|
redirect("/");
|
|
}
|
|
|
|
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
|
|
if (!session?.user?.id) {
|
|
redirect("/auth/login");
|
|
}
|
|
|
|
return session;
|
|
}
|