From 4d0458b0e8b463bb7bed67039d705580b12732aa Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Tue, 16 Sep 2025 15:39:42 +0200 Subject: [PATCH] feat: add client-side auth protection to routing forms pages (#23743) * feat: add client-side auth protection to routing forms pages - Create RoutingFormsShell component with useRedirectToLoginIfUnauthenticated hook - Wrap form-edit, route-builder, and incomplete-booking pages with RoutingFormsShell - Ensures consistent auth behavior during client-side navigation - Maintains existing server-side auth protection - Fix ESLint warnings: replace 'any' types with 'unknown' types and add eslint-disable for restricted imports Co-Authored-By: eunjae@cal.com * refactor: clean up RoutingFormsShell implementation - Remove unused isPublic parameter from RoutingFormsShell component - Keep only essential client-side authentication protection functionality - Fix remaining ESLint warnings to allow commit to pass Co-Authored-By: eunjae@cal.com * remove unnecessary hook * use shell at layout * rename component --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../[...pages]/RoutingFormAuthGuard.tsx | 9 +++++++++ .../apps/routing-forms/[...pages]/layout.tsx | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 apps/web/app/(use-page-wrapper)/apps/routing-forms/[...pages]/RoutingFormAuthGuard.tsx 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.tsx new file mode 100644 index 0000000000..a6bb3b04ad --- /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.tsx index a31b1251b4..22594d160a 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 {children}; +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 {children}; + } + + return ( + + {children} + + ); }