Skip to content

Commit 994a36d

Browse files
fix: add authentication guard to /apps/installed routes (calcom#23092)
* fix: add authentication guard to /apps/installed routes - Add session validation before making tRPC calls in server component - Redirect unauthenticated users to /auth/login instead of throwing 500 errors - Follows existing authentication patterns used throughout the codebase - Fixes 500 error when accessing /apps/installed/calendar and other categories Co-Authored-By: alex@cal.com <me@alexvanandel.com> * fix: Missing return; was that so hard, DevinAI? --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent c989817 commit 994a36d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

  • apps/web/app/(use-page-wrapper)/apps/installed/[category]

apps/web/app/(use-page-wrapper)/apps/installed/[category]/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { createRouterCaller } from "app/_trpc/context";
22
import type { PageProps } from "app/_types";
33
import { _generateMetadata } from "app/_utils";
4+
import { cookies, headers } from "next/headers";
45
import { redirect } from "next/navigation";
56
import { z } from "zod";
67

8+
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
79
import { AppCategories } from "@calcom/prisma/enums";
810
import { appsRouter } from "@calcom/trpc/server/routers/viewer/apps/_router";
911
import { calendarsRouter } from "@calcom/trpc/server/routers/viewer/calendars/_router";
1012

13+
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
14+
1115
import InstalledApps from "~/apps/installed/[category]/installed-category-view";
1216

1317
const querySchema = z.object({
@@ -31,6 +35,11 @@ const InstalledAppsWrapper = async ({ params }: PageProps) => {
3135
redirect("/apps/installed/calendar");
3236
}
3337

38+
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
39+
if (!session?.user?.id) {
40+
return redirect("/auth/login");
41+
}
42+
3443
const [calendarsCaller, appsCaller] = await Promise.all([
3544
createRouterCaller(calendarsRouter),
3645
createRouterCaller(appsRouter),

0 commit comments

Comments
 (0)