From 401ebccafd9af2d429af92c4a660f86a87c2939d Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Thu, 7 May 2026 14:29:12 -0700 Subject: [PATCH] fix(auth): Redirect to login if user session doesn't exist (#4497) * feat(admin): Increase impersonation timeout to 100 years * fix(workspace): redirect to login on missing session instead of leaving blank workspace --- apps/sim/app/workspace/[workspaceId]/layout.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/sim/app/workspace/[workspaceId]/layout.tsx b/apps/sim/app/workspace/[workspaceId]/layout.tsx index 5fe6c2dbfe..5d253320ce 100644 --- a/apps/sim/app/workspace/[workspaceId]/layout.tsx +++ b/apps/sim/app/workspace/[workspaceId]/layout.tsx @@ -1,3 +1,4 @@ +import { redirect } from 'next/navigation' import { ToastProvider } from '@/components/emcn' import { getSession } from '@/lib/auth' import { NavTour } from '@/app/workspace/[workspaceId]/components/product-tour' @@ -13,8 +14,11 @@ import { getOrgWhitelabelSettings } from '@/ee/whitelabeling/org-branding' export default async function WorkspaceLayout({ children }: { children: React.ReactNode }) { const session = await getSession() + if (!session?.user) { + redirect('/login') + } // The organization plugin is conditionally spread so TS can't infer activeOrganizationId on the base session type. - const orgId = (session?.session as { activeOrganizationId?: string } | null)?.activeOrganizationId + const orgId = (session.session as { activeOrganizationId?: string } | null)?.activeOrganizationId const initialOrgSettings = orgId ? await getOrgWhitelabelSettings(orgId) : null return (