chore: remove user routes from middleware (#19345)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+19
-8
@@ -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 {
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -172,8 +172,6 @@ export const config = {
|
||||
"/routing-forms/:path*",
|
||||
"/team/:path*",
|
||||
"/org/:path*",
|
||||
"/:user/:type/",
|
||||
"/:user/",
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user