Skip to content

Scheduling infrastructure for absolutely everyone.

chore: remove user routes from middleware (#19345)

Benny Joo322137958439
diff --git a/apps/web/app/(use-page-wrapper)/[user]/[type]/page.tsx b/apps/web/app/(use-page-wrapper)/[user]/[type]/page.tsx
index 1e19cd0d50c..bb0f0f63b49 100644
--- a/apps/web/app/(use-page-wrapper)/[user]/[type]/page.tsx
+++ b/apps/web/app/(use-page-wrapper)/[user]/[type]/page.tsx
@@ -5,7 +5,7 @@ import { headers, cookies } from "next/headers";
import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";
-import { buildLegacyCtx } from "@lib/buildLegacyCtx";
+import { buildLegacyCtx, decodeParams } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@server/lib/[user]/[type]/getServerSideProps";
@@ -31,12 +31,14 @@ export const generateMetadata = async ({ params, searchParams }: PageProps) => {
})),
],
};
+ const decodedParams = decodeParams(params);
const metadata = await generateMeetingMetadata(
meeting,
(t) => `${rescheduleUid && !!booking ? t("reschedule") : ""} ${title} | ${profileName}`,
(t) => `${rescheduleUid ? t("reschedule") : ""} ${title}`,
isBrandingHidden,
- getOrgFullOrigin(eventData?.entity.orgSlug ?? null)
+ getOrgFullOrigin(eventData?.entity.orgSlug ?? null),
+ `/${decodedParams.user}/${decodedParams.type}`
);
return {
diff --git a/apps/web/app/(use-page-wrapper)/[user]/page.tsx b/apps/web/app/(use-page-wrapper)/[user]/page.tsx
index 8bc97b02b42..45c57cad0dd 100644
--- a/apps/web/app/(use-page-wrapper)/[user]/page.tsx
+++ b/apps/web/app/(use-page-wrapper)/[user]/page.tsx
@@ -5,7 +5,7 @@ import { headers, cookies } from "next/headers";
import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains";
-import { buildLegacyCtx } from "@lib/buildLegacyCtx";
+import { buildLegacyCtx, decodeParams } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@server/lib/[user]/getServerSideProps";
@@ -30,7 +30,8 @@ export const generateMetadata = async ({ params, searchParams }: PageProps) => {
() => profile.name,
() => markdownStrippedBio,
false,
- getOrgFullOrigin(entity.orgSlug ?? null)
+ getOrgFullOrigin(entity.orgSlug ?? null),
+ `/${decodeParams(params).user}`
);
return {
diff --git a/apps/web/app/_utils.tsx b/apps/web/app/_utils.tsx
index acda1dd5207..3331e452bc5 100644
--- a/apps/web/app/_utils.tsx
+++ b/apps/web/app/_utils.tsx
@@ -1,8 +1,9 @@
import { type TFunction } from "i18next";
import i18next from "i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
-import { headers } from "next/headers";
+import { cookies, headers } from "next/headers";
+import { getLocale } from "@calcom/features/auth/lib/getLocale";
import type { AppImageProps, MeetingImageProps } from "@calcom/lib/OgImages";
import { constructAppImage, constructGenericImage, constructMeetingImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG, CAL_URL } from "@calcom/lib/constants";
@@ -11,6 +12,8 @@ import { truncateOnWord } from "@calcom/lib/text";
//@ts-expect-error no type definitions
import config from "@calcom/web/next-i18next.config";
+import { buildLegacyRequest } from "@lib/buildLegacyCtx";
+
const i18nInstanceCache: Record<string, any> = {};
const createI18nInstance = async (locale: string, ns: string) => {
@@ -44,7 +47,7 @@ export const getTranslate = async () => {
const headersList = await headers();
// If "x-locale" does not exist in header,
// ensure that config.matcher in middleware includes the page you are testing
- const locale = headersList.get("x-locale");
+ const locale = headersList.get("x-locale") ?? (await getLocale(buildLegacyRequest(headersList, cookies())));
const t = await getTranslationWithCache(locale ?? "en");
return t;
};
@@ -53,12 +56,13 @@ const _generateMetadataWithoutImage = async (
getTitle: (t: TFunction<string, undefined>) => string,
getDescription: (t: TFunction<string, undefined>) => string,
hideBranding?: boolean,
- origin?: string
+ origin?: string,
+ pathname?: string
) => {
const h = headers();
- const pathname = h.get("x-pathname") ?? "";
- const canonical = buildCanonical({ path: pathname, origin: origin ?? CAL_URL });
- const locale = h.get("x-locale") ?? "en";
+ const _pathname = h.get("x-pathname") ?? pathname ?? "";
+ const canonical = buildCanonical({ path: _pathname, origin: origin ?? CAL_URL });
+ const locale = h.get("x-locale") ?? (await getLocale(buildLegacyRequest(h, cookies()))) ?? "en";
const t = await getTranslationWithCache(locale);
const title = getTitle(t);
@@ -110,9 +114,16 @@ export const generateMeetingMetadata = async (
getTitle: (t: TFunction<string, undefined>) => string,
getDescription: (t: TFunction<string, undefined>) => string,
hideBranding?: boolean,
- origin?: string
+ origin?: string,
+ pathname?: string
) => {
- const metadata = await _generateMetadataWithoutImage(getTitle, getDescription, hideBranding, origin);
+ const metadata = await _generateMetadataWithoutImage(
+ getTitle,
+ getDescription,
+ hideBranding,
+ origin,
+ pathname
+ );
const image = SEO_IMG_OGIMG + constructMeetingImage(meeting);
return {
diff --git a/apps/web/lib/buildLegacyCtx.tsx b/apps/web/lib/buildLegacyCtx.tsx
index 834a36a2016..f26f8a4e094 100644
--- a/apps/web/lib/buildLegacyCtx.tsx
+++ b/apps/web/lib/buildLegacyCtx.tsx
@@ -26,7 +26,7 @@ const buildLegacyCookies = (cookies: ReadonlyRequestCookies) => {
return createProxifiedObject(cookiesObject);
};
-function decodeParams(params: Params): Params {
+export function decodeParams(params: Params): Params {
return Object.entries(params).reduce((acc, [key, value]) => {
// Handle array values
if (Array.isArray(value)) {
diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts
index 18a26f2a249..f09d4b1c6c5 100644
--- a/apps/web/middleware.ts
+++ b/apps/web/middleware.ts
@@ -172,8 +172,6 @@ export const config = {
"/routing-forms/:path*",
"/team/:path*",
"/org/:path*",
- "/:user/:type/",
- "/:user/",
],
};