diff --git a/apps/web/src/app/(authenticated)/settings/users/page.tsx b/apps/web/src/app/(authenticated)/settings/users/page.tsx index 35b0f35..e177bf4 100644 --- a/apps/web/src/app/(authenticated)/settings/users/page.tsx +++ b/apps/web/src/app/(authenticated)/settings/users/page.tsx @@ -42,6 +42,7 @@ import { AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; +import { fetchUserWorkspaces } from "@/lib/api/workspaces"; import { deactivateUser, fetchAdminUsers, @@ -105,6 +106,8 @@ export default function UsersSettingsPage(): ReactElement { const [editError, setEditError] = useState(null); const [isEditing, setIsEditing] = useState(false); + const [isAdmin, setIsAdmin] = useState(null); + const loadUsers = useCallback(async (showLoadingState: boolean): Promise => { try { if (showLoadingState) { @@ -129,6 +132,20 @@ export default function UsersSettingsPage(): ReactElement { void loadUsers(true); }, [loadUsers]); + useEffect(() => { + fetchUserWorkspaces() + .then((workspaces) => { + const adminRoles: WorkspaceMemberRole[] = [ + WorkspaceMemberRole.OWNER, + WorkspaceMemberRole.ADMIN, + ]; + setIsAdmin(workspaces.some((ws) => adminRoles.includes(ws.role))); + }) + .catch(() => { + setIsAdmin(true); // fail open + }); + }, []); + function resetInviteForm(): void { setInviteForm(INITIAL_INVITE_FORM); setInviteError(null); @@ -212,6 +229,17 @@ export default function UsersSettingsPage(): ReactElement { } } + if (isAdmin === false) { + return ( +
+
+

Access Denied

+

You need Admin or Owner role to manage users.

+
+
+ ); + } + return (