Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/sim/app/_shell/providers/session-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type AppSession = {
emailVerified?: boolean
name?: string | null
image?: string | null
role?: string
createdAt?: Date
updatedAt?: Date
} | null
Expand Down
42 changes: 0 additions & 42 deletions apps/sim/app/api/user/super-user/route.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/sim/app/api/users/me/settings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function GET() {
emailPreferences: userSettings.emailPreferences ?? {},
billingUsageNotificationsEnabled: userSettings.billingUsageNotificationsEnabled ?? true,
showTrainingControls: userSettings.showTrainingControls ?? false,
superUserModeEnabled: userSettings.superUserModeEnabled ?? true,
superUserModeEnabled: userSettings.superUserModeEnabled ?? false,
errorNotificationsEnabled: userSettings.errorNotificationsEnabled ?? true,
snapToGridSize: userSettings.snapToGridSize ?? 0,
showActionBar: userSettings.showActionBar ?? true,
Expand Down
17 changes: 1 addition & 16 deletions apps/sim/app/templates/[id]/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function TemplateDetails({ isWorkspaceContext = false }: Template
const [currentUserOrgRoles, setCurrentUserOrgRoles] = useState<
Array<{ organizationId: string; role: string }>
>([])
const [isSuperUser, setIsSuperUser] = useState(false)
const isSuperUser = session?.user?.role === 'admin'
const [isUsing, setIsUsing] = useState(false)
const [isEditing, setIsEditing] = useState(false)
const [isApproving, setIsApproving] = useState(false)
Expand Down Expand Up @@ -186,21 +186,6 @@ export default function TemplateDetails({ isWorkspaceContext = false }: Template
}
}

const fetchSuperUserStatus = async () => {
if (!currentUserId) return

try {
const response = await fetch('/api/user/super-user')
if (response.ok) {
const data = await response.json()
setIsSuperUser(data.isSuperUser || false)
}
} catch (error) {
logger.error('Error fetching super user status:', error)
}
}

fetchSuperUserStatus()
fetchUserOrganizations()
}, [currentUserId])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import dynamic from 'next/dynamic'
import { useSearchParams } from 'next/navigation'
import { Skeleton } from '@/components/emcn'
import { useSession } from '@/lib/auth/auth-client'
import { AdminSkeleton } from '@/app/workspace/[workspaceId]/settings/components/admin/admin-skeleton'
import { ApiKeysSkeleton } from '@/app/workspace/[workspaceId]/settings/components/api-keys/api-key-skeleton'
import { BYOKSkeleton } from '@/app/workspace/[workspaceId]/settings/components/byok/byok-skeleton'
import { CopilotSkeleton } from '@/app/workspace/[workspaceId]/settings/components/copilot/copilot-skeleton'
import { CredentialSetsSkeleton } from '@/app/workspace/[workspaceId]/settings/components/credential-sets/credential-sets-skeleton'
import { CredentialsSkeleton } from '@/app/workspace/[workspaceId]/settings/components/credentials/credential-skeleton'
import { CustomToolsSkeleton } from '@/app/workspace/[workspaceId]/settings/components/custom-tools/custom-tool-skeleton'
import { DebugSkeleton } from '@/app/workspace/[workspaceId]/settings/components/debug/debug-skeleton'
import { GeneralSkeleton } from '@/app/workspace/[workspaceId]/settings/components/general/general-skeleton'
import { InboxSkeleton } from '@/app/workspace/[workspaceId]/settings/components/inbox/inbox-skeleton'
import { McpSkeleton } from '@/app/workspace/[workspaceId]/settings/components/mcp/mcp-skeleton'
Expand Down Expand Up @@ -130,10 +131,10 @@ const Inbox = dynamic(
import('@/app/workspace/[workspaceId]/settings/components/inbox/inbox').then((m) => m.Inbox),
{ loading: () => <InboxSkeleton /> }
)
const Debug = dynamic(
const Admin = dynamic(
() =>
import('@/app/workspace/[workspaceId]/settings/components/debug/debug').then((m) => m.Debug),
{ loading: () => <DebugSkeleton /> }
import('@/app/workspace/[workspaceId]/settings/components/admin/admin').then((m) => m.Admin),
{ loading: () => <AdminSkeleton /> }
)
const RecentlyDeleted = dynamic(
() =>
Expand All @@ -157,9 +158,15 @@ interface SettingsPageProps {
export function SettingsPage({ section }: SettingsPageProps) {
const searchParams = useSearchParams()
const mcpServerId = searchParams.get('mcpServerId')
const { data: session, isPending: sessionLoading } = useSession()

const isAdminRole = session?.user?.role === 'admin'
const effectiveSection =
!isBillingEnabled && (section === 'subscription' || section === 'team') ? 'general' : section
!isBillingEnabled && (section === 'subscription' || section === 'team')
? 'general'
: section === 'admin' && !sessionLoading && !isAdminRole
? 'general'
: section
Comment on lines 164 to +169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Admin section renders briefly for non-admin users

When sessionLoading is true and section === 'admin', the condition section === 'admin' && !sessionLoading && !isAdminRole evaluates to false (because !sessionLoading is false), so effectiveSection stays as 'admin' and <Admin /> is rendered — showing its skeleton to a potentially non-admin user until the session resolves.

This means a non-admin user who navigates directly to /settings/admin will briefly see the AdminSkeleton before being redirected to general. A safer pattern is to treat a loading session the same as a non-admin session for this section:

Suggested change
const effectiveSection =
!isBillingEnabled && (section === 'subscription' || section === 'team') ? 'general' : section
!isBillingEnabled && (section === 'subscription' || section === 'team')
? 'general'
: section === 'admin' && !sessionLoading && !isAdminRole
? 'general'
: section
const effectiveSection =
!isBillingEnabled && (section === 'subscription' || section === 'team')
? 'general'
: section === 'admin' && (sessionLoading || !isAdminRole)
? 'general'
: section

This ensures non-admin users never see any part of the Admin UI, even transiently. Admins will still see the General section skeleton briefly while the session loads, but that is less sensitive than leaking the Admin skeleton.


const label =
allNavigationItems.find((item) => item.id === effectiveSection)?.label ?? effectiveSection
Expand All @@ -185,7 +192,7 @@ export function SettingsPage({ section }: SettingsPageProps) {
{effectiveSection === 'workflow-mcp-servers' && <WorkflowMcpServers />}
{effectiveSection === 'inbox' && <Inbox />}
{effectiveSection === 'recently-deleted' && <RecentlyDeleted />}
{effectiveSection === 'debug' && <Debug />}
{effectiveSection === 'admin' && <Admin />}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Skeleton } from '@/components/emcn'

export function AdminSkeleton() {
return (
<div className='flex h-full flex-col gap-[24px]'>
<div className='flex items-center justify-between'>
<Skeleton className='h-[14px] w-[120px]' />
<Skeleton className='h-[20px] w-[36px] rounded-full' />
</div>
<div className='flex flex-col gap-[8px]'>
<Skeleton className='h-[14px] w-[340px]' />
<div className='flex gap-[8px]'>
<Skeleton className='h-9 flex-1 rounded-[6px]' />
<Skeleton className='h-9 w-[80px] rounded-[6px]' />
</div>
</div>
<div className='flex flex-col gap-[8px]'>
<Skeleton className='h-[14px] w-[120px]' />
<Skeleton className='h-[200px] w-full rounded-[8px]' />
</div>
</div>
)
}
Loading
Loading