Skip to content

Scheduling infrastructure for absolutely everyone.

fix: move admin permission check to server-side to prevent flash (#23517)

Eunjae Lee34d2a130805e
diff --git a/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/AdminLayoutAppDirClient.tsx b/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/AdminLayoutAppDirClient.tsx
index b4733515e4e..ce9d4bbfdae 100644
--- a/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/AdminLayoutAppDirClient.tsx
+++ b/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/AdminLayoutAppDirClient.tsx
@@ -1,11 +1,11 @@
"use client";
-import { usePathname, useRouter } from "next/navigation";
+import { usePathname } from "next/navigation";
import type { ComponentProps } from "react";
-import React, { useEffect } from "react";
+import React from "react";
import type Shell from "@calcom/features/shell/Shell";
-import { UserPermissionRole } from "@calcom/prisma/enums";
+import type { UserPermissionRole } from "@calcom/prisma/enums";
import { ErrorBoundary } from "@calcom/ui/components/errorBoundary";
export type AdminLayoutProps = {
@@ -14,14 +14,6 @@ export type AdminLayoutProps = {
} & ComponentProps<typeof Shell>;
export default function AdminLayoutAppDirClient({ userRole, children }: AdminLayoutProps) {
const pathname = usePathname();
- const router = useRouter();
-
- // Force redirect on component level
- useEffect(() => {
- if (userRole !== UserPermissionRole.ADMIN) {
- router.replace("/settings/my-account/profile");
- }
- }, [userRole, router]);
const isAppsPage = pathname?.startsWith("/settings/admin/apps");
return (
diff --git a/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/layout.tsx b/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/layout.tsx
index bf2bfed9fda..a0911b0cce2 100644
--- a/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/layout.tsx
+++ b/apps/web/app/(use-page-wrapper)/settings/(admin-layout)/layout.tsx
@@ -1,7 +1,9 @@
import { cookies, headers } from "next/headers";
+import { redirect } from "next/navigation";
import React from "react";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+import { UserPermissionRole } from "@calcom/prisma/enums";
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
@@ -15,5 +17,9 @@ export default async function AdminLayoutAppDir(props: AdminLayoutAppDirProps) {
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
const userRole = session?.user?.role;
+ if (userRole !== UserPermissionRole.ADMIN) {
+ return redirect("/settings/my-account/profile");
+ }
+
return await SettingsLayoutAppDir({ children: <AdminLayoutAppDirClient {...props} userRole={userRole} /> });
}