Skip to content

Commit 401ebcc

Browse files
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
1 parent f708462 commit 401ebcc

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

apps/sim/app/workspace/[workspaceId]/layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { redirect } from 'next/navigation'
12
import { ToastProvider } from '@/components/emcn'
23
import { getSession } from '@/lib/auth'
34
import { NavTour } from '@/app/workspace/[workspaceId]/components/product-tour'
@@ -13,8 +14,11 @@ import { getOrgWhitelabelSettings } from '@/ee/whitelabeling/org-branding'
1314

1415
export default async function WorkspaceLayout({ children }: { children: React.ReactNode }) {
1516
const session = await getSession()
17+
if (!session?.user) {
18+
redirect('/login')
19+
}
1620
// The organization plugin is conditionally spread so TS can't infer activeOrganizationId on the base session type.
17-
const orgId = (session?.session as { activeOrganizationId?: string } | null)?.activeOrganizationId
21+
const orgId = (session.session as { activeOrganizationId?: string } | null)?.activeOrganizationId
1822
const initialOrgSettings = orgId ? await getOrgWhitelabelSettings(orgId) : null
1923

2024
return (

0 commit comments

Comments
 (0)