Files
calendar/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx
T
Benny JooandGitHub f86a5db843 chore: App Router Migration, add metadata to getting-started, extract into /modules and add method to UserRepository (#16449)
* getting-started: extract into /modules

* fix

* fix type-check

* add findByIdWithOptionalSelect to UserRepository

* fix import error

* fix type check

* add metadata

* fix
2024-09-17 02:42:19 +00:00

40 lines
1.1 KiB
TypeScript

import type { GetServerSidePropsContext } from "next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { getLocale } from "@calcom/features/auth/lib/getLocale";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { UserRepository } from "@calcom/lib/server/repository/user";
import { ssrInit } from "@server/lib/ssr";
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const { req } = context;
const session = await getServerSession({ req });
if (!session?.user?.id) {
return { redirect: { permanent: false, destination: "/auth/login" } };
}
const ssr = await ssrInit(context);
await ssr.viewer.me.prefetch();
const user = await UserRepository.findUserTeams({
id: session.user.id,
});
if (!user) {
throw new Error("User from session not found");
}
const locale = await getLocale(context.req);
return {
props: {
...(await serverSideTranslations(locale || "en", ["common"])),
trpcState: ssr.dehydrate(),
hasPendingInvites: user.teams.find((team) => team.accepted === false) ?? false,
},
};
};