Files
calendar/packages/features/ee/organizations/pages/organization.tsx
T
Benny JooandGitHub f0dc3bba17 chore: tech debt clearing - getServerSession has a dead arg: res (#19053)
* remove res from arg list in getServerSession

* remove res from all usages of getServerSession
2025-02-03 00:12:42 -05:00

47 lines
1.3 KiB
TypeScript

import type { GetServerSidePropsContext } from "next";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { getFeatureFlag } from "@calcom/features/flags/server/utils";
import { MembershipRole } from "@calcom/prisma/client";
export const getServerSideProps = async ({ req }: GetServerSidePropsContext) => {
const prisma = await import("@calcom/prisma").then((mod) => mod.default);
const organizationsEnabled = await getFeatureFlag(prisma, "organizations");
// Check if organizations are enabled
if (!organizationsEnabled) {
return {
notFound: true,
} as const;
}
// Check if logged in user has an organization assigned
const session = await getServerSession({ req });
if (!session?.user.profile?.organizationId) {
return {
notFound: true,
} as const;
}
// Check if logged in user has OWNER/ADMIN role in organization
const membership = await prisma.membership.findFirst({
where: {
userId: session?.user.id,
teamId: session?.user.profile.organizationId,
},
select: {
role: true,
},
});
if (!membership?.role || membership?.role === MembershipRole.MEMBER) {
return {
notFound: true,
} as const;
}
// Otherwise, all good
return {
props: {},
};
};