perf: replace getServerSessionForAppDir usages with our original getServerSession function (#18897)
This commit is contained in:
@@ -4,7 +4,9 @@ import { notFound } from "next/navigation";
|
||||
import { cache } from "react";
|
||||
import { z } from "zod";
|
||||
|
||||
// import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
|
||||
// import { cookies, headers } from "next/headers";
|
||||
// import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
// import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
import { ScheduleRepository } from "@calcom/lib/server/repository/schedule";
|
||||
|
||||
// import { TravelScheduleRepository } from "@calcom/lib/server/repository/travelSchedule";
|
||||
@@ -47,7 +49,7 @@ const Page = async ({ params }: PageProps) => {
|
||||
}
|
||||
// const scheduleId = Number(params.schedule);
|
||||
|
||||
// const session = await getServerSessionForAppDir();
|
||||
// const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
|
||||
// const userId = session?.user?.id;
|
||||
// if (!userId) {
|
||||
// notFound();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
// import { cookies, headers } from "next/headers";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
// import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
|
||||
// import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
// import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
// import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
|
||||
import AvailabilityPage from "~/availability/availability-view";
|
||||
|
||||
@@ -13,7 +15,7 @@ export const generateMetadata = async () => {
|
||||
};
|
||||
|
||||
const Page = async () => {
|
||||
// const session = await getServerSessionForAppDir();
|
||||
// const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
|
||||
// const userId = session?.user?.id;
|
||||
// const orgId = session?.user?.org?.id;
|
||||
// if (!userId || !orgId) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { _generateMetadata } from "app/_utils";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getServerSessionForAppDir } from "@calcom/features/auth/lib/get-server-session-for-app-dir";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
|
||||
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
||||
|
||||
@@ -19,7 +19,7 @@ export const generateMetadata = async () =>
|
||||
|
||||
const Page = async ({ params, searchParams }: PageProps) => {
|
||||
const context = buildLegacyCtx(headers(), cookies(), params, searchParams);
|
||||
const session = await getServerSessionForAppDir();
|
||||
const session = await getServerSession({ req: context.req });
|
||||
if (!session?.user?.id) {
|
||||
redirect("/auth/login");
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import { notFound } from "next/navigation";
|
||||
import { cache } from "react";
|
||||
import { z } from "zod";
|
||||
|
||||
// import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
|
||||
// import { cookies, headers } from "next/headers";
|
||||
// import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
// import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
import LegacyPage from "@calcom/features/ee/workflows/pages/workflow";
|
||||
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
|
||||
@@ -38,8 +40,7 @@ export const generateMetadata = async ({ params }: PageProps): Promise<Metadata
|
||||
export const generateStaticParams = () => [];
|
||||
|
||||
const Page = async ({ params }: PageProps) => {
|
||||
// FIXME: Refactor me once next-auth endpoint is migrated to App Router
|
||||
// const session = await getServerSessionForAppDir();
|
||||
// const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
|
||||
// const user = session?.user;
|
||||
const parsed = querySchema.safeParse(params);
|
||||
if (!parsed.success) {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { PageProps } from "app/_types";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
|
||||
// import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
|
||||
// import { cookies, headers } from "next/headers";
|
||||
// import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
// import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
// import { getTeamsFiltersFromQuery } from "@calcom/features/filters/lib/getTeamsFiltersFromQuery";
|
||||
// import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
import LegacyPage from "@calcom/features/ee/workflows/pages/index";
|
||||
@@ -13,8 +15,7 @@ export const generateMetadata = async () =>
|
||||
);
|
||||
|
||||
const Page = async ({ params, searchParams }: PageProps) => {
|
||||
// FIXME: Refactor me once next-auth endpoint is migrated to App Router
|
||||
// const session = await getServerSessionForAppDir();
|
||||
// const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
|
||||
// const user = session?.user;
|
||||
|
||||
// const filters = getTeamsFiltersFromQuery({ ...searchParams, ...params });
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getServerSessionForAppDir } from "@calcom/features/auth/lib/get-server-session-for-app-dir";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
const RedirectPage = async () => {
|
||||
const session = await getServerSessionForAppDir();
|
||||
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
|
||||
|
||||
if (!session?.user?.id) {
|
||||
redirect("/auth/login");
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,9 +1,12 @@
|
||||
import dynamic from "next/dynamic";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import React from "react";
|
||||
|
||||
import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
|
||||
import SettingsLayoutAppDir from "@calcom/features/settings/appDir/SettingsLayoutAppDir";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
import SettingsLayoutAppDir from "../(settings-layout)/SettingsLayoutAppDir";
|
||||
import type { AdminLayoutProps } from "./AdminLayoutAppDirClient";
|
||||
|
||||
const AdminLayoutAppDirClient = dynamic(() => import("./AdminLayoutAppDirClient"), {
|
||||
@@ -13,8 +16,7 @@ const AdminLayoutAppDirClient = dynamic(() => import("./AdminLayoutAppDirClient"
|
||||
type AdminLayoutAppDirProps = Omit<AdminLayoutProps, "userRole">;
|
||||
|
||||
export default async function AdminLayoutAppDir(props: AdminLayoutAppDirProps) {
|
||||
// FIXME: Refactor me once next-auth endpoint is migrated to App Router
|
||||
const session = await getServerSessionForAppDir();
|
||||
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
|
||||
const userRole = session?.user?.role;
|
||||
|
||||
return await SettingsLayoutAppDir({ children: <AdminLayoutAppDirClient {...props} userRole={userRole} /> });
|
||||
@@ -1,5 +1,5 @@
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
|
||||
import { getLayout } from "@components/auth/layouts/AdminLayoutAppDir";
|
||||
import { getLayout } from "./AdminLayoutAppDir";
|
||||
|
||||
export default WithLayout({ getServerLayout: getLayout })<"L">;
|
||||
|
||||
+5
-2
@@ -1,9 +1,12 @@
|
||||
import dynamic from "next/dynamic";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import React from "react";
|
||||
|
||||
import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
import type { SettingsLayoutProps } from "./SettingsLayoutAppDirClient";
|
||||
|
||||
const SettingsLayoutAppDirClient = dynamic(() => import("./SettingsLayoutAppDirClient"), {
|
||||
@@ -13,7 +16,7 @@ const SettingsLayoutAppDirClient = dynamic(() => import("./SettingsLayoutAppDirC
|
||||
type SettingsLayoutAppDir = Omit<SettingsLayoutProps, "currentOrg" | "otherTeams">;
|
||||
|
||||
export default async function SettingsLayoutAppDir(props: SettingsLayoutAppDir) {
|
||||
const session = await getServerSessionForAppDir();
|
||||
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
|
||||
const userId = session?.user?.id ?? -1;
|
||||
const orgId = session?.user?.org?.id ?? -1;
|
||||
let currentOrg = null;
|
||||
@@ -1,5 +1,5 @@
|
||||
import { WithLayout } from "app/layoutHOC";
|
||||
|
||||
import { getLayout } from "@calcom/features/settings/appDir/SettingsLayoutAppDir";
|
||||
import { getLayout } from "./SettingsLayoutAppDir";
|
||||
|
||||
export default WithLayout({ getServerLayout: getLayout })<"L">;
|
||||
|
||||
@@ -3,7 +3,8 @@ import { WithLayout } from "app/layoutHOC";
|
||||
|
||||
import LegacyPage from "@calcom/features/ee/organizations/pages/members";
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import SettingsLayoutAppDir from "@calcom/features/settings/appDir/SettingsLayoutAppDir";
|
||||
|
||||
import SettingsLayoutAppDir from "../../(settings-layout)/SettingsLayoutAppDir";
|
||||
|
||||
export const generateMetadata = async () =>
|
||||
await _generateMetadata(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { SearchParams } from "app/_types";
|
||||
import { type Params } from "app/_types";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
import type { GetServerSidePropsContext, NextApiRequest } from "next";
|
||||
import { type ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
|
||||
import { type ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
|
||||
|
||||
@@ -45,6 +45,10 @@ function decodeParams(params: Params): Params {
|
||||
}, {} as Params);
|
||||
}
|
||||
|
||||
export const buildLegacyRequest = (headers: ReadonlyHeaders, cookies: ReadonlyRequestCookies) => {
|
||||
return { headers: buildLegacyHeaders(headers), cookies: buildLegacyCookies(cookies) } as NextApiRequest;
|
||||
};
|
||||
|
||||
export const buildLegacyCtx = (
|
||||
headers: ReadonlyHeaders,
|
||||
cookies: ReadonlyRequestCookies,
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
import { getOptions } from "./next-auth-options";
|
||||
|
||||
export async function getServerSessionForAppDir() {
|
||||
return await getServerSession(
|
||||
getOptions({
|
||||
getDubId: () => cookies().get("dub_id")?.value || cookies().get("dclid")?.value,
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user