Skip to content

Commit 34d2a13

Browse files
fix: move admin permission check to server-side to prevent flash (calcom#23517)
- Move permission validation from AdminLayoutAppDirClient.tsx (client) to layout.tsx (server) - Add server-side redirect using next/navigation redirect() function - Remove client-side useEffect permission check to eliminate flash - Follow same pattern as organizations layout for consistent auth handling - Users without admin role are redirected to /settings/my-account/profile before any content renders Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 6066ed2 commit 34d2a13

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

apps/web/app/(use-page-wrapper)/settings/(admin-layout)/AdminLayoutAppDirClient.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use client";
22

3-
import { usePathname, useRouter } from "next/navigation";
3+
import { usePathname } from "next/navigation";
44
import type { ComponentProps } from "react";
5-
import React, { useEffect } from "react";
5+
import React from "react";
66

77
import type Shell from "@calcom/features/shell/Shell";
8-
import { UserPermissionRole } from "@calcom/prisma/enums";
8+
import type { UserPermissionRole } from "@calcom/prisma/enums";
99
import { ErrorBoundary } from "@calcom/ui/components/errorBoundary";
1010

1111
export type AdminLayoutProps = {
@@ -14,14 +14,6 @@ export type AdminLayoutProps = {
1414
} & ComponentProps<typeof Shell>;
1515
export default function AdminLayoutAppDirClient({ userRole, children }: AdminLayoutProps) {
1616
const pathname = usePathname();
17-
const router = useRouter();
18-
19-
// Force redirect on component level
20-
useEffect(() => {
21-
if (userRole !== UserPermissionRole.ADMIN) {
22-
router.replace("/settings/my-account/profile");
23-
}
24-
}, [userRole, router]);
2517

2618
const isAppsPage = pathname?.startsWith("/settings/admin/apps");
2719
return (

apps/web/app/(use-page-wrapper)/settings/(admin-layout)/layout.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { cookies, headers } from "next/headers";
2+
import { redirect } from "next/navigation";
23
import React from "react";
34

45
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
6+
import { UserPermissionRole } from "@calcom/prisma/enums";
57

68
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
79

@@ -15,5 +17,9 @@ export default async function AdminLayoutAppDir(props: AdminLayoutAppDirProps) {
1517
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
1618
const userRole = session?.user?.role;
1719

20+
if (userRole !== UserPermissionRole.ADMIN) {
21+
return redirect("/settings/my-account/profile");
22+
}
23+
1824
return await SettingsLayoutAppDir({ children: <AdminLayoutAppDirClient {...props} userRole={userRole} /> });
1925
}

0 commit comments

Comments
 (0)