Scheduling infrastructure for absolutely everyone.
feat: add client-side auth protection to routing forms pages (#23743)
Eunjae Lee4d0458b0e8b4
diff --git a/apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/RoutingFormAuthGuard.tsx b/apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/RoutingFormAuthGuard.tsxnew file mode 100644index 00000000000..a6bb3b04ad4--- /dev/null+++ b/apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/RoutingFormAuthGuard.tsx@@ -0,0 +1,9 @@+"use client";++import { useRedirectToLoginIfUnauthenticated } from "@calcom/features/auth/lib/hooks/useRedirectToLoginIfUnauthenticated";++export function RoutingFormAuthGuard({ children }: { children: React.ReactNode }) {+ useRedirectToLoginIfUnauthenticated();++ return <>{children}</>;+}diff --git a/apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/layout.tsx b/apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/layout.tsxindex a31b1251b48..22594d160a2 100644--- a/apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/layout.tsx+++ b/apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/layout.tsx@@ -1,7 +1,22 @@import type { ReactNode } from "react";import FormProvider from "./FormProvider";+import { RoutingFormAuthGuard } from "./RoutingFormAuthGuard";-export default async function Layout({ children }: { children: ReactNode }) {- return <FormProvider>{children}</FormProvider>;+interface LayoutProps {+ children: ReactNode;+ params: { pages: string[] };+}++export default async function Layout({ children, params }: LayoutProps) {+ const isPublic = params.pages?.[0] === "routing-link";+ if (isPublic) {+ return <FormProvider>{children}</FormProvider>;+ }++ return (+ <RoutingFormAuthGuard>+ <FormProvider>{children}</FormProvider>+ </RoutingFormAuthGuard>+ );}