Skip to content

Commit

Permalink
chore: remove user routes from middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Feb 18, 2025
1 parent 9a271f3 commit 612c427
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
6 changes: 4 additions & 2 deletions apps/web/app/(use-page-wrapper)/[user]/[type]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions apps/web/app/(use-page-wrapper)/[user]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 {
Expand Down
27 changes: 19 additions & 8 deletions apps/web/app/_utils.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) => {
Expand Down Expand Up @@ -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;
};
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/buildLegacyCtx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 0 additions & 2 deletions apps/web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ export const config = {
"/routing-forms/:path*",
"/team/:path*",
"/org/:path*",
"/:user/:type/",
"/:user/",
],
};

Expand Down

0 comments on commit 612c427

Please sign in to comment.